Java code coverage tools: Difference between revisions

Content deleted Content added
Godin (talk | contribs)
JaCoCo 0.8.4
Bender the Bot (talk | contribs)
m EMMA: HTTP to HTTPS for SourceForge
 
(42 intermediate revisions by 33 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 41 ⟶ 76:
{{Clear}}
 
== JaCoCoOpenClover ==
{{Infobox software
| name = JaCoCoOpenClover
| developer = MarcMarek HoffmannParfianowicz, BrockGrzegorz Janiczak, Evgeny Mandrikov, Mirko FriedenhagenLewandowski
| latest release versionlatest_release_version = 04.85.42
| latest release datelatest_release_date = {{Release date and age|20192024|0501|0831}}
| genre = [[Code coverage]]
| license = [[Eclipse PublicApache License|EPL 2.0]]
| website = {{URL|https://www.jacocoopenclover.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.
 
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–2017.<ref>[http://openclover.org/about-us OpenClover - About us]</ref>
=== Features ===
JaCoCo offers instructions, line and branch coverage.
 
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.
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)
 
OpenClover integrates with [[Apache Ant|Ant]], [[Apache Maven|Maven]], [[Gradle]], [[Grails (framework)|Grails]], [[Eclipse (software)|Eclipse]], [[IntelliJ IDEA]], [[Bamboo (software)|Bamboo]], [[Jenkins (software)|Jenkins]], [[Hudson (software)|Hudson]], [[Griffon (framework)|Griffon]], [[SonarQube]] and AspectJ.
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 |dead-url=yes |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 and Java 11.
{{Clear}}
 
=== ToolsIntelliJ usingIDEA orCode includingCoverage JaCoCoAgent ===
{{Infobox software
* SonarQube JaCoCo plugin &mdash; one of the defaults for coverage analyses within the code quality management platform [[SonarQube]]
| name = IntelliJ IDEA Code Coverage Agent
* EclEmma [[Eclipse (software)]] Code Coverage Plugin, was formerly EMMA based<ref>[http://www.eclemma.org/ EclEmma, Eclipse code coverage plugin]</ref>
| developer = JetBrains
* [[Jenkins (software)|Jenkins]] JaCoCo Plugin<ref>[https://wiki.jenkins-ci.org/display/JENKINS/JaCoCo+Plugin Jenkins JaCoCo Plugin]</ref>
| latest_release_version =
* [[Netbeans]] JaCoCo support<ref>[http://wiki.netbeans.org/MavenCodeCoverage#Using_JaCoCo NetBeans JaCoCo support]</ref>
| latest_release_date =
* [[IntelliJ IDEA]] since v11<ref name=idea/>
| genre = [[Code coverage]]
* [[Gradle]] JaCoCo Plugin<ref>[http://www.gradle.org/docs/current/userguide/jacoco_plugin.html Gradle JaCoCo Plugin]</ref>
| license = [[Apache 2.0]]
* [[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>
| website = {{URL|https://github.com/JetBrains/intellij-coverage}}
* [[TeamCity]]<ref>[https://confluence.jetbrains.com/display/TCD10/JaCoCo JaCoCo integration in TeamCity]</ref>
}}
'''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}}
== Clover ==
 
== Testwell CTC++ for Java ==
{{Infobox software
| name = Testwell CTC++
| developer = Verifysoft Technology
| latest_release_version = 8.0.
| latest_release_date = {{Release date and age|2016|06|30}}
| genre = [[Code coverage]]
| license = [[Proprietary software|Proprietary]]
| website = {{URL|verifysoft.com/en_ctcpp.html}}
}}
'''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>
 
== Notable historic tools ==
 
=== Clover ===
{{Redirect|Clover (software)|the dating app|Clover (mobile app)}}
{{Infobox software
| name = Clover
| logo = Clover_software_Logo.svg
| developer = [[Atlassian]]
| latest release version = 4.1.2
Line 93 ⟶ 144:
 
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>
 
== OpenClover ==
{{Infobox software
| name = OpenClover
| developer = Marek Parfianowicz, Grzegorz Lewandowski
| latest_release_version = 4.3.1
| latest_release_date = {{Release date and age|2018|09|21}}
| genre = [[Code coverage]]
| license = [[Apache License 2.0]]
| website = {{URL|openclover.org}}
}}
 
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-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.
 
OpenClover integrates with [[Apache Ant|Ant]], [[Apache Maven|Maven]], [[Gradle]], [[Grails (framework)|Grails]], [[Eclipse (software)|Eclipse]], [[IntelliJ IDEA]], [[Bamboo (software)|Bamboo]], [[Jenkins (software)|Jenkins]], [[Hudson (software)|Hudson]], [[Griffon (framework)|Griffon]], [[SonarQube]] and AspectJ.
{{Clear}}
 
== Cobertura ==
Line 124 ⟶ 157:
}}
 
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 141 ⟶ 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 153 ⟶ 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).
 
=== EMMA-based tools ===
 
* SonarQube EMMA plugin—Enables usage of EMMA analyses within the code quality management platform [[SonarQube]]
* [http://code.google.com/webtoolkit/tools/download-codepro.html Google CodePro AnalytiX]
* [https://wiki.jenkins-ci.org/display/JENKINS/Emma+Plugin Jenkins Emma Plugin]
 
== Jtest ==
{{Infobox Software
| name = Jtest
| developer = [[Parasoft]]
| released = {{Start date and age|1997}}
| latest_release_version = 10.3.3
| latest_release_date = {{Start date and age|2017|11|07}}
| genre = [[Code coverage]]
| language = English, Chinese, Japanese
| license = [[Proprietary software|Proprietary]] [[commercial software]]
| website = {{URL|https://www.parasoft.com/products/jtest/}}
}}
 
'''Jtest''' is an automated [[Java platform|Java]] [[software testing]] tool that is made by [[Parasoft]]. The product includes code coverage as well as other testing technologies such as [[Data-flow analysis]] [[Unit testing|Unit test-case generation and execution]], [[Static code analysis|static analysis]], [[regression testing]], and [[runtime error detection]].
<ref>[http://java.sys-con.com/read/299985.htm JDJ Product Review - Parasoft Jtest 8.0] by Jason Bell, Java Developers Journal (JDJ), November 17, 2006</ref>
 
Jtest can gather coverage from a variety of frameworks as well as types of testing including unit test, functional testing or manual testing. Through integration with [[Parasoft Concerto|Parasoft DTP]] the coverage from these different types of testing can be accurately merged to create a single coverage score.<ref>{{cite web|url=https://blog.parasoft.com/testing-123-change-based-testing-coverage |title=Testing 123 with Parasoft's Mark Lambert: Change-Based Testing and Merged Correlated Code Coverage|date=2016-12-01 |accessdate=2018-02-08}}</ref>
 
Jtest can be run from an eclipse-based GUI, command line mode, or integrated with [[Continuous integration|CI]] systems.
 
Advanced reporting and analytics are performed using Parasoft DTP and include capabilities for:
*[[Traceability|Test-to-code traceability]]
*[[Requirements traceability]]
*Merged coverage (from multiple runs or tools)
*Change-based testing - correlating which tests must be run based on code that changed
 
== Serenity ==
Line 200 ⟶ 201:
| website = {{URL|https://wiki.jenkins-ci.org/display/JENKINS/Serenity+Plugin}}
}}
'''Serenity''' is an [[open-source software|open-source]] toolkittool forcreating measuringbetter-automated software acceptance tests in less time. It and measures and reportingreports [[Java (programming language)|Java]] [[code coverage]]. AsIt wellalso asgenerates coverage,easy-to-understand majorreports codethat metricsdescribe arewhat measured:-the cyclometric complexity, stability,application abstractnessdoes and distancehow fromit main.works, Theincluding reportwhich datatests iswere persisted to an object database,run and made[https://serenity-bdd.info/what-is-serenity/ availablewhat viarequirements Jenkins/Hudsonwere met]. TheIt interfaceworks replicateswith theSelenium EclipseWebDriver, IDEAppium, and interfaceBDD visuallytools.
 
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:
Line 225 ⟶ 228:
Jenkins slaves as well as Maven multi module projects are supported.
 
== Testwell CTC++ for JavaReferences ==
{{Reflist}}
{{Infobox software
| name = Testwell CTC++
| developer = Verifysoft Technology
| latest_release_version = 8.0.
| latest_release_date = {{Release date and age|2016|06|30}}
| genre = [[Code coverage]]
| license = [[Proprietary software|Proprietary]]
| website = {{URL|verifysoft.com/en_ctcpp.html}}
}}
'''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>
 
== Citations ==
== IntelliJ IDEA Code Coverage Agent ==
* {{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}}
{{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}}
 
== See also ==
* {{Portal-inline|Software Testing}}
 
== References ==
<references/>
 
== 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]