ArticleslgStudy

computer science

Java code coverage tools

Java code coverage tools is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Java code coverage tools rather than just read about it. In short: Java code coverage tools are of two types: first, tools that add statements to the Java source code and require its recompilation. Second, tools that instrument the bytecode, either before or during execution.

Java code coverage tools — main illustration
Java code coverage tools — illustration

Key takeaways

  • Java code coverage tools belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Java code coverage tools to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Java code coverage tools from memory before moving on to harder problems.

Reference excerpt

Java code coverage tools are of two types: first, tools that add statements to the 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 executed when running a test.

JaCoCo

JaCoCo is an open-source toolkit for measuring and reporting Java code coverage. JaCoCo is distributed under the terms of the Eclipse Public License. It was developed as a replacement for EMMA, under the umbrella of the EclEmma plug-in for Eclipse.

Features JaCoCo offers instructions, line and branch coverage. In contrast to Atlassian Clover and OpenClover, which require instrumenting the source code, JaCoCo can instrument Java bytecode using two different approaches:

like JCov on the fly while running the code with a Java agent like Cobertura and 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. Unlike Cobertura and EMMA it fully supports Java 7, Java 8, 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 — one of the defaults for coverage analyses within the code quality management platform SonarQube EclEmma Eclipse (software) Code Coverage Plugin, was formerly EMMA based Jenkins JaCoCo Plugin Netbeans JaCoCo support IntelliJ IDEA since v11 Gradle JaCoCo Plugin Maven JaCoCo Plugin Visual Studio Team Services TeamCity STAMP (https://www.stamp-project.eu/)

JCov

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 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 JCov is capable of reporting the following types of code coverage:

Block coverage Line coverage Branch coverage Method coverage JCov implements two different ways to save the collected data:

Into a file on the filesystem Onto a server (a.k.a. "network grabber") JCov works by instrumenting Java bytecode using two different approaches:

Static instrumentation which is done upfront, changing the tested code Dynamic instrumentation which is done on the fly by means of Java agent JCov has a few more distinctive features which include, but are not limited to:

Field coverage Abstract API coverage Direct/indirect coverage Per-test coverage information (a.k.a. "test scales") Public API and SPI which makes it possible to implement custom filtering and/or mining the coverage data

Tools using JCov Oracle JDK (SE and ME) JCK (the Java Compatibility Kit) Various Java SE and Java ME TCKs Java FX SDK Java FX Scene Builder

OpenClover

OpenClover is a free and open-source successor of Atlassian Clover, created as a 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. OpenClover uses source code instrumentation technique and handles Java, Groovy and AspectJ languages. Some of its features include: fine control over scope of coverage measurement, test optimisation and sophisticated reports. OpenClover integrates with Ant, Maven, Gradle, Grails, Eclipse, IntelliJ IDEA, Bamboo, Jenkins, Hudson, Griffon, SonarQube and AspectJ.

IntelliJ IDEA Code Coverage Agent

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.

Testwell CTC++ for Java

Testwell CTC++ is a code coverage tool for C, C++, Java and 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. The tool works with all compilers.

Notable historic tools

Clover

Clover is a Java code coverage analysis utility bought and further developed by Atlassian. In April 2017 Atlassian announced end-of-life of Clover and at the same time open-sourced it under Apache 2.0 license. Clover uses a source code instrumentation technique (as opposed to Cobertura and JaCoCo, which use byte code instrumentation), which has its advantages (such as an ability to collect code metrics) and disadvantages (re-compilation of sources is necessary). Some of its features include historical reporting, huge control over the coverage gathering process, command line toolset and API for legacy integration and more. Clover also allows testing time to be reduced by only running the tests that cover the application code that was modified since the previous build. This is called Test Optimization and can lead to huge drops in the amount of time spent waiting for automated tests to complete. Clover comes with a number of integrations both developed by Atlassian (Ant, Maven, Grails, Eclipse, IDEA, Bamboo) and by open source community (Gradle, Griffon, Jenkins, Hudson, Sonar). 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.

Cobertura

Cobertura is an open-source tool for measuring code coverage. It does so by instrumenting the byte code. It was the predecessor to JaCoCo.

EMMA

EMMA is an open-source toolkit for measuring and reporting 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. EMMA works by wrapping each line of code and each condition with a flag, which is set when that line is executed.

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Java code coverage tools

Start with the simplest possible case. Write down what Java code coverage tools claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Java code coverage tools before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Java code coverage tools ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Java code coverage tools

In research
Java code coverage tools appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Java code coverage tools in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Java code coverage tools is common in secondary-school and first-year university syllabi. It links to neighbouring topics Java development tools, Software testing tools, so understanding it makes those chapters shorter.
In everyday life
Look for Java code coverage tools outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Java code coverage tools” →

How to study Java code coverage tools in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Java code coverage tools means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Java code coverage tools out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Java code coverage tools in simple terms?

Java code coverage tools are of two types: first, tools that add statements to the Java source code and require its recompilation. Second, tools that instrument the bytecode, either before or during execution.

Why does Java code coverage tools matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Java code coverage tools?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Java code coverage tools.

Tags

  • Java development tools
  • Software testing tools

Keep exploring