Popular Open Source Code Coverage Tools for Java

java code coverage tools - open source

The process of software development can be a long and tedious one because it involves understanding, building, writing and testing if what you have developed meets the objectives. There are different approaches that are used during software development including pair programming, unit testing, code convention, code review, test-driven development and continuous integration among others.

The difference is in the approach that you use to write and test the source code to verify if it is working as expected.

As you develop and test your software, you need to run automated tests to know how many units, lines, statements or blocks of your code are being tested.

The effectiveness of automated tests is determined by measuring the code coverage which is the percentage of your code that is not covered by automated tests and therefore likely to have defects.

To do this, you need code coverage tools that are compatible with the development language that you are using, and the following are some of the best open source tools for Java.

CodeCover

CodeCover is an open source glass- box testing tool for COBOL and Java that was developed in 2007. Glass-box testing technology examines program structure and derives test data from the code. This comes with many benefits including greater traceability, removal of redundant tests cases, increased test coverage and testing of adequacy metric.

It measures metrics such as statement, ranch, loop, term coverage, question mark operator coverage and synchronized coverage. CodeCover generates reports using template engine velocity and is integrated with Ant, JUnit, Eclipse and Jenkins.

Cobertura

Cobertura is an old but popular open source code coverage utility for Java that allows you to execute tasks through Ant, Gradle, Maven and CLI. It is based on jcoverage and is extensible so that you can create your own metrics and report formats although it is no longer actively maintained and does not support the current versions of Java.

If you are finding it hard to work with, you need to learn a few Cobertura tricks that will make it easy to work on your own Java code base.

Serenity BDD

This is an automated acceptance testing tool that has code coverage as one of its features. Last released in 2016, it works by writing epics and stories for each behavior path which it monitors testing coverage for.

These stories produce executable specifications that are run on automated tests for execution and reporting. It integrates with a variety of tools including Jenkins, JIra, Sauce Labs, Appiumm, BrowserStack and so on.

PITest

Unlike other code coverage tools, PITest uses mutation testing technology described as the gold standard test coverage for Java and JVM. This means that it not only displays the number of lines of code that are tested but also how your automated tests are discovering bugs.

This is because it is able to modify your code before running tests on it. PITest integrates with Ant, Maven, Eclipse, InteliJ and Gradle.

EMMA

EMMA was last released in 2005 and although it one of the oldest code coverage tools for Java, it remains popular. It supports many types of coverage including class, line, method and lock although like Cobertura, it is no longer actively maintained and does not support the current version of Java.

For this reason, JACOCO was created to replace it in powering the EclEmma plugin which integrates with many tools including Ant, Maven, Jenkins, Visual Studio and Gradle.

Code coverage measurements are very important if you want to understand the quality of your QA tests. Whether you are a single developer or part of a large team, there are numerous code coverage tools that are available for different programming languages and integrate with all tools in your toolset.

About The Author: noeticsophia

Sophia is the contributing editor at noeticforce.com. She writes about anything and everything that makes modern mobile apps, web apps and websites possible. Passionate about coding in any language including Python, Swift, JavaScript, PHP, Java, Android & iOS dev, not excluding CSS/HTML. 

If you like this article, you can connect with noeticforce on Twitter or subscribe to noeticforce feed via RSS.