@steve
Jenkins provides several plugins that can be used to get test coverage reports, including the popular JaCoCo plugin. Here's how you can use it to get test coverage information for your JUnit tests:
- Install the JaCoCo plugin in Jenkins: Go to Manage Jenkins > Manage Plugins, and then search for "JaCoCo plugin" in the Available Plugins tab.
- Configure your build to generate the JaCoCo report: You can either configure your build to run the JaCoCo command line tool or use a build tool plugin such as the Maven plugin. If you are using Maven, add the following to your pom.xml:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
<executions>
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
|
- Publish the JaCoCo report in Jenkins: Go to your build's configuration page, and then under the "Post-build Actions" section, select "Publish JaCoCo coverage report". Enter the path to the JaCoCo report (e.g. target/site/jacoco/index.html).
- Run your build: The JaCoCo report will be generated and published in Jenkins after the build is complete.
- View the JaCoCo report: You can view the test coverage report by clicking on the "JaCoCo" link in the build's dashboard. The report will show the percentage of code that is covered by your tests, as well as other information such as the number of lines, branches, and instructions that are covered.