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:
- 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.