Generating an HTML report highlighting new coverage
To visualize the new coverage gained by writing tests with Diffblue Cover CLI,
a subcommand called
coverage-diff that generates a JaCoCo HTML report with the new coverage
explicitly highlighted. For example, after writing tests for the
java-demo example as described
here the report might look as follows:
The new coverage is shown in blue in coverage bars and as percentage increases, and for each
coverage counter in the right portion of the table (cyclomatic complexity, lines, methods and
classes) a column called
Increased is added with the total number of newly covered elements.
JaCoCo Java Code Coverage is a widely used code coverage report
generator. For example, to use it in a Maven project add the following declarations to the
<dependency> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.8.5</version> </dependency>
<plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.8.5</version> <executions> <execution> <goals> <goal>prepare-agent</goal> </goals> </execution> <execution> <id>report</id> <phase>test</phase> <goals> <goal>report</goal> </goals> </execution> </executions> </plugin>
mvn test will now result in creating a coverage report in binary format called
jacoco.exec in the
target directory of your Maven project. The report will also be interpreted
in a readable code coverage report in HTML format in
Generating an HTML report with new coverage
To generate the HTML report, use
dcover with subcommand
For example, running the following command from the root of the
dcover coverage-diff target/jacocoOld.exec target/jacocoNew.exec
will generate the HTML report for a coverage report
target/jacocoNew.exec while highlighting
the increase in coverage compared to a coverage report
Additional optional arguments may also be provided:
--classpath or -cp
Provide the path to class files of the project you want to generate the HTML report for.
Multiple paths can be specified using
: as separators for Linux/macOS and
; for Windows.
All packages, classes and methods found in the listed directories and jar files will show
in the generated report and at least all files of the project itself must be on the path.
For example, if a jar with dependencies is provided then all packages and classes from
the dependencies will be appear in the coverage report.
--source-dir or -s
Provide the relative path for the directory with source files. The source files are part of the HTML report and the coverage is marked using green and red lines. Note that at the moment, the newly covered lines are also shown in green, i.e., not distinguished from the old coverage.
--report-output-dir or -d
Provide the relative path for the directory where the HTML report should be saved.
Set the working directory for running
dcover, which should be the root directory of the project or module.
If provided, all paths specified in other options should be either absolute or relative to the working directory.
This is also used for setting the report header.