Prerequisites
- A running Jenkins server (version 2.x or later)
- Jenkins plugins: Pipeline, JUnit, JaCoCo (v3.2.0+)
- A Spring Boot project with Maven build (
pom.xml) - Git repository with sample tests under
src/test/java
1. Review the Unit Test Cases
Navigate tosrc/test/java and inspect the NumericApplicationTests class. It uses MockMvc to validate HTTP endpoints:
2. Update Your Jenkinsfile to Run Unit Tests
Open the rootJenkinsfile. If you only build the artifact, insert a dedicated Unit Tests stage to execute mvn test:

3. Configure JaCoCo in pom.xml
To collect coverage data, add the JaCoCo Maven plugin under the <build><plugins> section:
The
prepare-agent goal instruments bytecode before tests, while the report goal generates HTML/XML coverage reports in target/site/jacoco.4. Publish JUnit and JaCoCo Reports in Jenkins
Ensure the Jenkins JaCoCo plugin (v3.2.0+) is installed under Manage Jenkins → Installed Plugins:

Any untested code (e.g., methods without assertions) will show 0% coverage. Add test cases to improve your coverage metrics.