Workshop for mutation testing with Pitest. In this project I use Groovy and Spock for testing simply because I like it better than JUnit. However Pitest works just fine for Junit as well.
In order to use Pitest into our Maven project we just need to add the plugin ito our pom.xml like this.
Note that the timestampedReports configuration will cause Pitest to not put its reports into timestamped directories but overwrite old reports. This makes it easier to find the report after running the analysis.
Also note that the execution configuration will cause Pitest to run every time you run mvn install or verify. Since mutation testing takes a lot of time you might want to move this into a profile or just run mvn install pitest:mutationCoverage manually.
In order to get the mutation test coverage information into your Sonar:
- Install local SonarQube for testing.
I personally use Docker for that, simply running
docker run -d --name sonarqube -p 9000:9000 -p 9092:9092 sonarqubeIf everything worked, you should see a SonarQube here. - Run
mvn install sonar:sonarto create the project. If that worked, you should find your analysis here. You won't find any mutation data for now, since we are missing required plugins. - Install plugins for Groovy and Pitest:
- Login to your local SonarQube (user name and password should be both "admin").
- Go to Update Center and find "Groovy" and "Pitest" and click the "Install" button.
- Scroll up and click "Restart" button to finish the installation.
- Make sure you have the
sonar.pitest.modeproperty set, otherwise SonarQube plugin will simply ignore the mutation coverage data. - When you now run
mvn install sonar:sonaryou will find a new kind of measure named mutation analysis - Optionally active the additional coding rules
- Checkout User and UserClassSpec.
- Run Pitest via
mvn install pitest:mutationCoverage, open the report and try to understand it. - Run Sonar analysis via
mvn sonar:sonarand check the mutation analysis in SonarQube. - Try to "kill" the remaining mutations one by one.