Java code coverage tools: Difference between revisions

Content deleted Content added
No edit summary
Bender the Bot (talk | contribs)
m EMMA: HTTP to HTTPS for SourceForge
 
(31 intermediate revisions by 26 users not shown)
Line 1:
{{Short description|Java development tools}}
'''Java code coverage tools''' are of two types: first, tools that add statements to the [[Java (programming language)|Java]] [[source code]] and require its recompilation. Second, tools that instrument the [[bytecode]], either before or during execution. The goal is to find out which parts of the code are tested by registering the lines of [[code coverage|code executed]] when running a test.
 
== JaCoCo ==
{{Infobox software
| name = JaCoCo
| developer = Marc Hoffmann, Brock Janiczak, Evgeny Mandrikov, Mirko Friedenhagen
| latest release version = 0.8.12
| latest release date = {{Release date and age|2024|03|31}}
| genre = [[Code coverage]]
| license = [[Eclipse Public License|EPL]]
| website = {{URL|https://www.jacoco.org/jacoco}}
}}
'''JaCoCo''' is an [[open-source software|open-source]] toolkit for measuring and reporting [[Java (programming language)|Java]] [[code coverage]]. JaCoCo is distributed under the terms of the [[Eclipse Public License]]. It was developed as a replacement for EMMA,<ref name="jacocomission">[http://www.eclemma.org/jacoco/trunk/doc/mission.html JaCoCo Mission]</ref> under the umbrella of the EclEmma plug-in for Eclipse.
 
=== Features ===
JaCoCo offers instructions, line and branch coverage.
 
In contrast to [[#Clover|Atlassian Clover]] and [[#OpenClover|OpenClover]], which require instrumenting the source code, JaCoCo can instrument [[Java bytecode]] using two different approaches:
* like [[#JCov|JCov]] on the fly while running the code with a Java agent<ref>{{cite web |url=http://onlysoftware.wordpress.com/2012/12/19/code-coverage-tools-jacoco-cobertura-emma-comparison-in-sonar/ |title=Code Coverage Tools (JaCoCo, Cobertura, Emma) Comparison in Sonar|author=Patroklos Papapetrou|date=19 December 2012 |work=Only Software matters |publisher= |accessdate=3 March 2013}}</ref>
* like [[#Cobertura|Cobertura]] and [[#JCov|JCov]] prior to execution (offline)
 
And can be configured to store the collected data in a file, or send it via TCP. Files from multiple runs or code parts can be merged easily.<ref>{{Cite web |url=http://www.sonarsource.org/measure-coverage-by-integration-tests-with-sonar-updated/ |title=Measure Coverage by Integration Tests with Sonar – Updated |access-date=2013-03-01 |archive-date=2013-02-23 |archive-url=https://web.archive.org/web/20130223183723/http://www.sonarsource.org/measure-coverage-by-integration-tests-with-sonar-updated/ |url-status=dead }}</ref> Unlike Cobertura and [[#EMMA|EMMA]] it fully supports Java 7, Java 8,<ref name="idea">{{cite web|url=http://www.jetbrains.com/idea/webhelp/code-coverage-2.html |archive-url=https://archive.today/20130426184708/http://www.jetbrains.com/idea/webhelp/code-coverage-2.html |url-status=dead |archive-date=26 April 2013 |title=Code Coverage |author= |date= |work=IntelliJ IDEA 12.0 Web Help |publisher=JetBrains |accessdate=3 March 2013 }}</ref> Java 9, Java 10, Java 11, Java 12, Java 13, Java 14, Java 15, Java 16, Java 17, Java 18, Java 19 and Java 20.
 
=== Tools using or including JaCoCo ===
* SonarQube JaCoCo plugin &mdash; one of the defaults for coverage analyses within the code quality management platform [[SonarQube]]
* EclEmma [[Eclipse (software)]] Code Coverage Plugin, was formerly EMMA based<ref>[http://www.eclemma.org/ EclEmma, Eclipse code coverage plugin]</ref>
* [[Jenkins (software)|Jenkins]] JaCoCo Plugin<ref>[https://wiki.jenkins-ci.org/display/JENKINS/JaCoCo+Plugin Jenkins JaCoCo Plugin]</ref>
* [[Netbeans]] JaCoCo support<ref>{{Cite web |url=http://wiki.netbeans.org/MavenCodeCoverage#Using_JaCoCo |title=NetBeans JaCoCo support |access-date=2013-02-22 |archive-date=2012-05-31 |archive-url=https://web.archive.org/web/20120531150325/http://wiki.netbeans.org/MavenCodeCoverage#Using_JaCoCo |url-status=dead }}</ref>
* [[IntelliJ IDEA]] since v11<ref name=idea/>
* [[Gradle]] JaCoCo Plugin<ref>[http://www.gradle.org/docs/current/userguide/jacoco_plugin.html Gradle JaCoCo Plugin]</ref>{{sfn|Gulati|Sharma|2017|loc=Chapter §6 Integrating Tools - Build Tools - Gradle|pp=99-103}}
* [[Apache Maven|Maven]] JaCoCo Plugin<ref>[https://www.jacoco.org/jacoco/trunk/doc/maven.html Maven JaCoCo Plugin]</ref>{{sfn|Gulati|Sharma|2017|loc=Chapter §6 Integrating Tools - Build Tools - Maven Extension|p=115}}
* [[Visual Studio Team Services]]<ref>[https://blogs.msdn.microsoft.com/devops/2015/11/24/testing-java-applications-with-visual-studio-team-services/ JaCoCo integration in Visual Studio Team Services]</ref>
* [[TeamCity]]<ref>[https://confluence.jetbrains.com/display/TCD10/JaCoCo JaCoCo integration in TeamCity]</ref>
* STAMP (https://www.stamp-project.eu/{{Dead link|date=April 2023 |bot=InternetArchiveBot |fix-attempted=yes }})<ref>[https://github.com/STAMP-project/dspot#test-selectors--s----test-criterion Jacoco is used by STAMP DSpot tool as a test selector (seen as a fitness) to select tests that increase the coverage and have unique executed path]</ref>
 
 
== JCov ==
Line 12 ⟶ 47:
}}
 
JCov is the tool which has been developed and used with Sun JDK (and later Oracle JDK) from the very beginning of Java: from the version 1.1. JCov is capable of measuring and reporting [[Java (programming language)|Java]] [[code coverage]]. JCov is distributed under the terms of the [[GNU General Public License]] (version 2, with the Classpath Exception). JCov has become open-source as a part of [[OpenJDK]] code tools project in 2014.
 
=== Features ===
Line 40 ⟶ 75:
* Java FX Scene Builder
{{Clear}}
 
== JaCoCo ==
{{Infobox software
| name = JaCoCo
| developer = Marc Hoffmann, Brock Janiczak, Evgeny Mandrikov, Mirko Friedenhagen
| latest release version = 0.8.4
| latest release date = {{Release date and age|2019|05|08}}
| genre = [[Code coverage]]
| license = [[Eclipse Public License|EPL]]
| website = {{URL|https://www.jacoco.org/jacoco}}
}}
'''JaCoCo''' is an [[open-source software|open-source]] toolkit for measuring and reporting [[Java (programming language)|Java]] [[code coverage]]. JaCoCo is distributed under the terms of the [[Eclipse Public License]]. It was developed as a replacement for EMMA,<ref name="jacocomission">[http://www.eclemma.org/jacoco/trunk/doc/mission.html JaCoCo Mission]</ref> under the umbrella of the EclEmma plug-in for Eclipse.
 
=== Features ===
JaCoCo offers instructions, line and branch coverage.
 
In contrast to [[Java code coverage tools#Clover|Atlassian Clover]] and [[Java code coverage tools#OpenClover|OpenClover]], which require instrumenting the source code, JaCoCo can instrument Java bytecode using two different approaches:
* like [[Java code coverage tools#JCov|JCov]] on the fly while running the code with a Java agent<ref>{{cite web |url=http://onlysoftware.wordpress.com/2012/12/19/code-coverage-tools-jacoco-cobertura-emma-comparison-in-sonar/ |title=Code Coverage Tools (JaCoCo, Cobertura, Emma) Comparison in Sonar|author=Patroklos Papapetrou|date=19 December 2012 |work=Only Software matters |publisher= |accessdate=3 March 2013}}</ref>
* like [[Java code coverage tools#Cobertura|Cobertura]] and [[Java code coverage tools#JCov|JCov]] prior to execution (offline)
 
And can be configured to store the collected data in a file, or send it via TCP. Files from multiple runs or code parts can be merged easily.<ref>[http://www.sonarsource.org/measure-coverage-by-integration-tests-with-sonar-updated/ Measure Coverage by Integration Tests with Sonar – Updated]</ref> Unlike Cobertura and [[Java code coverage tools#EMMA|EMMA]] it fully supports Java 7, Java 8,<ref name="idea">{{cite web|url=http://www.jetbrains.com/idea/webhelp/code-coverage-2.html |archive-url=https://archive.is/20130426184708/http://www.jetbrains.com/idea/webhelp/code-coverage-2.html |url-status=dead |archive-date=26 April 2013 |title=Code Coverage |author= |date= |work=IntelliJ IDEA 12.0 Web Help |publisher=JetBrains |accessdate=3 March 2013 }}</ref> Java 9, Java 10, Java 11, Java 12 and Java 13.
 
=== Tools using or including JaCoCo ===
* SonarQube JaCoCo plugin &mdash; one of the defaults for coverage analyses within the code quality management platform [[SonarQube]]
* EclEmma [[Eclipse (software)]] Code Coverage Plugin, was formerly EMMA based<ref>[http://www.eclemma.org/ EclEmma, Eclipse code coverage plugin]</ref>
* [[Jenkins (software)|Jenkins]] JaCoCo Plugin<ref>[https://wiki.jenkins-ci.org/display/JENKINS/JaCoCo+Plugin Jenkins JaCoCo Plugin]</ref>
* [[Netbeans]] JaCoCo support<ref>[http://wiki.netbeans.org/MavenCodeCoverage#Using_JaCoCo NetBeans JaCoCo support]</ref>
* [[IntelliJ IDEA]] since v11<ref name=idea/>
* [[Gradle]] JaCoCo Plugin<ref>[http://www.gradle.org/docs/current/userguide/jacoco_plugin.html Gradle JaCoCo Plugin]</ref>
* [[Visual Studio Team Services]]<ref>[https://blogs.msdn.microsoft.com/devops/2015/11/24/testing-java-applications-with-visual-studio-team-services/ JaCoCo integration in Visual Studio Team Services]</ref>
* [[TeamCity]]<ref>[https://confluence.jetbrains.com/display/TCD10/JaCoCo JaCoCo integration in TeamCity]</ref>
* STAMP (https://www.stamp-project.eu/)<ref>[https://github.com/STAMP-project/dspot#test-selectors--s----test-criterion Jacoco is used by STAMP DSpot tool as a test selector (seen as a fitness) to select tests that increase the coverage and have unique executed path]</ref>
 
== OpenClover ==
Line 77 ⟶ 80:
| name = OpenClover
| developer = Marek Parfianowicz, Grzegorz Lewandowski
| latest_release_version = 4.45.02
| latest_release_date = {{Release date and age|20192024|0901|2631}}
| genre = [[Code coverage]]
| license = [[Apache License 2.0]]
Line 84 ⟶ 87:
}}
 
OpenClover is a free and open-source successor of Atlassian Clover, created as a [[Fork (software development)|fork]] from the Clover code base published by Atlassian in 2017. It contains all features of the original Clover (the server edition). The OpenClover project is led by developers who maintained Clover in years 2012-20172012–2017.<ref>[http://openclover.org/about-us OpenClover - About us]</ref>
 
OpenClover uses source code instrumentation technique and handles Java, [[Apache Groovy|Groovy]] and [[AspectJ]] languages. Some of its features include: fine control over scope of coverage measurement, test optimisation and sophisticated reports.
Line 91 ⟶ 94:
{{Clear}}
 
== IntelliJ IDEA Code Coverage Agent ==
== Cobertura ==
{{Infobox software
| name = CoberturaIntelliJ IDEA Code Coverage Agent
| developer = Steven ChristouJetBrains
| latest_release_version =
| latest release version = 2.1.1
| latest_release_date =
| latest release date = {{Release date and age|2015|02|26}}
| genre = [[Code coverage]]
| license = GPL[[Apache 2.0]]
| repowebsite = {{URL|https://github.com/coberturaJetBrains/coberturaintellij-coverage}}
| website = {{URL|https://cobertura.github.io/cobertura/}}
}}
'''IntelliJ IDEA Code Coverage Agent''' is a [[code coverage]] tool integrated in IntelliJ IDEA IDE and TeamCity CI server. It supports branch coverage and per-test coverage tracking.
 
Cobertura is an [[open-source software|open-source]] tool for measuring code coverage. It does so by instrumenting the byte code.
 
{{Clear}}
 
== Serenity ==
{{Infobox software
| name = Serenity
| developer = Michael Couck
| latest release version = 1.0
| latest release date = {{Release date and age|2013|12|08}}
| genre = [[Code coverage]]
| license = [[Apache Software License]] version 2.0
| website = {{URL|https://wiki.jenkins-ci.org/display/JENKINS/Serenity+Plugin}}
}}
'''Serenity''' is an [[open-source software|open-source]] toolkit for measuring and reporting [[Java (programming language)|Java]] [[code coverage]]. As well as coverage, major code metrics are measured:- cyclometric complexity, stability, abstractness and distance from main. The report data is persisted to an object database, and made available via Jenkins/Hudson. The interface replicates the Eclipse IDE interface visually.
 
Serenity dynamically enhances the byte code, making a post-compile step unnecessary. Ant and Maven projects are supported. Configuration is done in xml, an Ant example would be:
 
<syntaxhighlight lang="xml">
<!-- Serenity system properties. -->
<sysproperty key="included.packages" value="your.package.name.here" />
<sysproperty key="included.adapters" value="coverage,complexity,dependency" />
<!-- Serenity JVM command line. -->
<jvmarg line="-javaagent:serenity/serenity.jar" />
</syntaxhighlight>
 
And a Maven configuration example would be:
<syntaxhighlight lang="xml">
<properties>
<included.packages>-Dincluded.packages=your.package.name.here</included.packages>
<included.adapters>-Dincluded.adapters=coverage,complexity,dependency</included.adapters>
</properties>
<argLine>-javaagent:serenity/serenity.jar -Xms512m -Xmx1024m ${included.packages} ${included.adapters}</argLine>
</syntaxhighlight>
 
For a full example of a configuration please refer to the Jenkins wiki at https://wiki.jenkins-ci.org/display/JENKINS/Serenity+Plugin.
 
Jenkins slaves as well as Maven multi module projects are supported.
 
== Testwell CTC++ for Java ==
Line 153 ⟶ 119:
}}
'''Testwell CTC++''' is a [[code coverage]] tool for [[C (programming language)|C]], [[C++]], [[Java (programming language)|Java]] and [[C Sharp (programming language)|C#]]. The development of this tool started in 1989 at Testwell in Finland. Since 2013 support and development has been continued by Verifysoft Technology, a company from [[Offenburg]], [[Germany]]. Testwell CTC++ analyses for all code coverage levels up to [[Modified condition/decision coverage]] and Multicondition Coverage.<ref name="Testwell CTC++ analyses for all coverage levels">[http://www.verifysoft.com/en_ctcpp_all_code_coverage_levels.html Testwell CTC++ supports all coverage levels]</ref> The tool works with all [[compilers]].<ref name="Testwell CTC++ supports all compilers">[http://www.verifysoft.com/en_code_coverage_all_compilers.html Testwell CTC++ supports all compilers]</ref>
 
== IntelliJ IDEA Code Coverage Agent ==
{{Infobox software
| name = IntelliJ IDEA Code Coverage Agent
| developer = JetBrains
| latest_release_version =
| latest_release_date =
| genre = [[Code coverage]]
| license = [[Apache 2.0]]
| website = {{URL|https://github.com/JetBrains/intellij-coverage}}
}}
'''IntelliJ IDEA Code Coverage Agent''' is a [[code coverage]] tool integrated in IntelliJ IDEA IDE and TeamCity CI server. It supports branch coverage and per-test coverage tracking.
 
{{Clear}}
 
== Notable historic tools ==
Line 174 ⟶ 126:
{{Infobox software
| name = Clover
| logo = Clover_software_Logo.svg
| developer = [[Atlassian]]
| latest release version = 4.1.2
Line 192 ⟶ 145:
In April 2017, Atlassian announced that they would no longer release new versions of Clover after version 4.1.2, and its code was made available as [[open-source software]] hosted on [[Bitbucket]].<ref>{{cite web|url=https://www.atlassian.com/blog/announcements/atlassian-clover-open-source|title=Atlassian Clover is now open source|website=atlassian.com|date=11 April 2017}}</ref><ref>{{cite web|url=https://bitbucket.org/atlassian/clover|title=atlassian/clover|website=bitbucket.org}}</ref>
 
== EMMACobertura ==
{{Infobox software
| name = Cobertura
| developer = Steven Christou
| latest release version = 2.1.1
| latest release date = {{Release date and age|2015|02|26}}
| genre = [[Code coverage]]
| license = GPL 2.0
| repo = {{URL|https://github.com/cobertura/cobertura}}
| website = {{URL|https://cobertura.github.io/cobertura/}}
}}
 
Cobertura is an [[open-source software|open-source]] tool for measuring code coverage. It does so by instrumenting the byte code. It was the predecessor to JaCoCo.
 
{{Clear}}
 
=== EMMA ===
{{Infobox software
| name = EMMA
Line 205 ⟶ 174:
'''EMMA''' is an [[open-source software|open-source]] toolkit for measuring and reporting [[Java (programming language)|Java]] [[code coverage]]. EMMA is distributed under the terms of [[Common Public License]] v1.0.
 
EMMA is not currently under active development; the last stable release took place in mid-2005. As replacement, JaCoCo was developed.<ref>[httphttps://sourceforge.net/projects/emma/files/ EMMA code coverage files on SourceForge.net]</ref>
EMMA works by wrapping each line of code and each condition with a flag, which is set when that line is executed.<ref>[https://books.google.com/books?id=L7d0LNpSrRwC&pg=PA289&dq=EMMA+%28code+coverage+tool%29&hlpg=en&ei=_pXATYmrJqrv0gHoroirBQ&sa=X&oi=book_result&ct=result&resnum=8&ved=0CG0Q6AEwBw#v=onepage&q&f=falsePA289 Expert Spring MVC and Web Flow; By Seth Ladd, Darren Davison, Steven Devijver, Colin Yates, p. 289]</ref>
 
==== Features ====
* instrument classes for coverage either offline (before they are loaded) or on the fly (using an instrumenting application classloader).
* Supported coverage types: class, method, line, basic block. EMMA can detect when a single source code line is covered only partially.
Line 217 ⟶ 186:
* it is possible to dump or reset coverage data remotely and without a JVM exit.
* does not require access to the source code and degrades gracefully with decreasing amount of debug information available in the input classes.
* can instrument individual <code>.class</code> files or entire <code>.jars</code> (in place, if desired). Efficient coverage subset filtering is possible, too.
* Makefile and ANT build integration are supported on equal footing.
* The runtime overhead of added instrumentation is small (5–20%) and the bytecode instrumentor itself is very fast (mostly limited by file I/O speed). Memory overhead is a few hundred bytes per Java class.
* EMMA is 100% pure Java, has no external library dependencies, and works in any Java 2 JVM (even 1.2.x).
 
== See alsoSerenity ==
{{Infobox software
| name = Serenity
| developer = Michael Couck
| latest release version = 1.0
| latest release date = {{Release date and age|2013|12|08}}
| genre = [[Code coverage]]
| license = [[Apache Software License]] version 2.0
| website = {{URL|https://wiki.jenkins-ci.org/display/JENKINS/Serenity+Plugin}}
}}
'''Serenity''' is an [[open-source software|open-source]] tool creating better-automated software acceptance tests in less time. It and measures and reports [[Java (programming language)|Java]] [[code coverage]]. It also generates easy-to-understand reports that describe what the application does and how it works, including which tests were run and [https://serenity-bdd.info/what-is-serenity/ what requirements were met]. It works with Selenium WebDriver, Appium, and BDD tools.
 
Major code metrics such as [[Cyclomatic complexity|cyclometric complexity]], stability, abstractness, and distance from main are measured. The report data is persisted to an [[object database]] and made available via Jenkins/Hudson. The interface visually replicates the Eclipse IDE interface.
 
Serenity dynamically enhances the byte code, making a post-compile step unnecessary. Ant and Maven projects are supported. Configuration is done in xml, an Ant example would be:
 
<syntaxhighlight lang="xml">
<!-- Serenity system properties. -->
<sysproperty key="included.packages" value="your.package.name.here" />
<sysproperty key="included.adapters" value="coverage,complexity,dependency" />
<!-- Serenity JVM command line. -->
<jvmarg line="-javaagent:serenity/serenity.jar" />
</syntaxhighlight>
 
And a Maven configuration example would be:
<syntaxhighlight lang="xml">
<properties>
<included.packages>-Dincluded.packages=your.package.name.here</included.packages>
<included.adapters>-Dincluded.adapters=coverage,complexity,dependency</included.adapters>
</properties>
<argLine>-javaagent:serenity/serenity.jar -Xms512m -Xmx1024m ${included.packages} ${included.adapters}</argLine>
</syntaxhighlight>
 
For a full example of a configuration please refer to the Jenkins wiki at https://wiki.jenkins-ci.org/display/JENKINS/Serenity+Plugin.
 
Jenkins slaves as well as Maven multi module projects are supported.
 
== References ==
{{Reflist}}
<references/>
 
== Citations ==
* {{cite book | last=Gulati | first=Shekhar | last2=Sharma | first2=Rahul | title=Java Unit Testing with JUnit 5 | publisher=[[Apress]] | publication-place=Berkeley, CA | year=2017 | isbn=978-1-4842-3014-5 | doi=10.1007/978-1-4842-3015-2}}
 
== External links ==
* [http://openclover.org/doc/manual/4.2.0/general--comparison-of-code-coverage-tools.html Comparison of OpenClover, Clover, Cobertura, JaCoCo, JCov, CodeCover and PIT]
* [http://kurlenda.blogspot.ch/2010/12/test-coverage-jacoco-vs-clover2.html JaCoCo vs Clover2]
* [http://www.sonarsource.org/pick-your-code-coverage-tool-in-sonar-2-2/ Pick your code coverage tool in Sonar 2.2] {{Webarchive|url=https://web.archive.org/web/20130223183739/http://www.sonarsource.org/pick-your-code-coverage-tool-in-sonar-2-2/ |date=2013-02-23 }}, a little outdated, as JaCoCo meanwhile supports branch coverage
* [https://blogs.msdn.microsoft.com/visualstudioalm/2015/11/24/testing-java-applications-with-visual-studio-team-services/ Testing Java Applications with Visual Studio Team Services]