Let us now include code coverage from the unit tests of our project in the site documentation.
Use the following steps to generate code coverage reports for a site:
project-with-documentation
).<build>
section of the pom.xml
file:<plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.7.2.201409121644</version> <executions> <execution> <id>default-prepare-agent</id> <goals> <goal>prepare-agent</goal> </goals> </execution> </executions> </plugin>
reporting
section of the pom.xml
file:<plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.7.2.201409121644</version> </plugin>
mvn test site
The JaCoCo unit test coverage report shows up in site documentation on account of the following issues:
prepare-agent
goal of the JaCoCo plugin is added to the build
section, Maven runs the JaCoCo agenttest
goal is run, Maven runs the test and the agent analyzes the tests for coveragereporting
section of the pom.xml
file, the coverage report is generated and linked to the site documentationbuild
and reporting
section and does different thingsIf you were to use Cobertura instead of JaCoCo to generate test coverage, you could do the following:
build
and reporting
sections.pom.xml
file:<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <version>2.6</version> </plugin>
mvn site
build
sectiontest
goal explicitly; the Maven Cobertura plugin did this.3.12.123.189