Skip to main content
In this tutorial, you’ll learn how to integrate PIT Mutation Testing into a Spring Boot project, execute mutation tests, and publish the HTML report in Jenkins. We’ll walk through:
  1. Configuring the Maven POM
  2. Updating the Jenkinsfile
  3. Installing and configuring the PIT plugin in Jenkins
  4. Running the pipeline and diagnosing failures
  5. Inspecting coverage and mutation results
  6. Strengthening unit tests to kill mutations
  7. Re-running tests and accessing reports

Table of Contents

  1. Configure Maven POM
  2. Update Jenkinsfile for Mutation Tests
  3. Install PIT Plugin in Jenkins
  4. Run Pipeline & Analyze Failures
  5. Inspect Coverage & Mutation Reports
  6. Understanding PIT Mutators
  7. Improve Tests to Kill Mutations
  8. Re-Run Mutation Tests
  9. Access Reports on Jenkins Agent

1. Configure Maven POM

Open your pom.xml and ensure you have Spring Boot and JaCoCo configured. Then add the PIT plugin:
The <mutationThreshold> of 70% fails the build if the mutation score is below 70%. Reports are generated under target/pit-reports.

2. Update Jenkinsfile for Mutation Tests

Add a dedicated stage for PIT after unit tests. Use this example pipeline:

3. Install PIT Plugin in Jenkins

  1. Go to Manage Jenkins → Manage Plugins
  2. Search for PIT Mutation Plugin and install
  3. Configure the report path:
The image shows the "Manage Jenkins" dashboard, displaying various configuration and management options for Jenkins, a popular automation server.

4. Run Pipeline & Analyze Failures

Trigger the Jenkins pipeline. If the mutation score is below threshold, the stage will fail:
The image shows a Jenkins pipeline dashboard with a stage view, indicating a failed build due to a shell script error. It includes build history, average stage times, and a code coverage trend graph.
A low mutation score indicates untested code paths. Strengthen your tests to catch mutated behavior.

5. Inspect Coverage & Mutation Reports

Even on failure, Jenkins archives test reports. View the JaCoCo summary:
The image shows a Jenkins build page for "Build #14" with details such as build artifacts, changes, and a Jacoco coverage summary. The coverage summary includes metrics like instruction, branch, complexity, line, method, and class coverage.
Click PIT Mutation Report for detailed mutation stats:
The image shows a Jenkins dashboard with details of a mutation testing report, including active mutators and tests examined. It also displays a list of mutators like BOOLEAN_FALSE_RETURN and CONDITIONALS_BOUNDARY_MUTATOR.

6. Understanding PIT Mutators

PIT applies mutators that change your code to test the effectiveness of your tests. Example: Conditional boundary mutator
Example: Return values mutator
Surviving mutations imply missing assertions in your tests.

7. Improve Tests to Kill Mutations

Consider this REST controller:
The image shows a screenshot of a code editor with Java code, including REST controller methods and mutation testing results. There is also a browser window with multiple tabs open at the top.
Existing tests only checked status codes, allowing some mutations to survive. Update your tests to assert response content:

8. Re-Run Mutation Tests

Re-trigger the pipeline. A successful mutation stage should look like:
You’ll see an 80% mutation score and full HTML reports.

9. Access Reports on Jenkins Agent

On your Jenkins server:
Open index.html in a browser to explore the complete mutation report.
Congratulations! You’ve successfully integrated PIT mutation testing, configured Jenkins for automated reporting, identified weak spots, and enhanced your tests for robust coverage.

Watch Video

Practice Lab