Sonar Pitest Plugin
The goal of this plugin is to bring PIT results to sonarSonarQubeTM. Right now the integration of these result results is quite simple, "survived mutants" on code covered by tests are seen as sonar violationsSonarQubeTM issues.
|Even if PIT detects "survived mutants" on uncovered lines of code, these mutants are simply ignored by the plugin.|
- Mutation testing is very CPU time expensive. It is really important to control the scope of mutation testing in order to keep acceptable sonar SonarQubeTM analysis times. See below for tips on analysis time.
- Mutation testing works on true unit tests. Do not try to use it on integration tests, you might mess up your database, file system, whatever external system used by your integration tests.
Henri Coles, creator of PIT, gave very useful tips on the PIT mailing list to help reduce PIT execution time:
Check out the "Advanced configuration properties" at the bottom of this page to address the above points.
SonarQubeTM server installation
On the sonar the SonarQubeTM side, just copy the sonar-pitest-plugin jar to the extensions/plugins directory just like any regular sonar SonarQubeTM plugin.
Since mutation testing is not (yet) officially supported by sonarSonarQubeTM, this plugin acts as a "single rule" rule engine... This rule, named "Survived mutant", is disabled by default and hence needs to be activated when pitest is used.
You have two options in order to produce PIT reports for sonarSonarQubeTM. You can either let the sonar plugin run PIT or you can run PIT prior to the sonar SonarQubeTM analysis.
PIT launched by
|There is a compatibility issue with maven 3.X|
The example above tells PIT to mutate classes from packages starting with "com.acme.tools.commons". It also specifies that test classes are located in packages starting with "com.acme.tools.commons".
PIT launched before
You can launch PIT using the PIT maven plugin or the command line runner. PIT execution must be done before sonar SonarQubeTM analysis. You also need to specify the "reuseReport" mode of the PIT sonar SonarQubeTM plugin.
Pit needs to be configured in order to generate XML reports. Be aware that PIT default behavior is to generate HTML reports. Below a simple configuration example for maven :
Last but not least, you need to run a sonar SonarQubeTM analysis with the PIT plugin activated in "reuseReport" mode. The following command would do the job :
"mvn sonar:sonar -Dsonar.pitest.mode=reuseReport"
By default sonar SonarQubeTM will search the latest PIT report in "target/pit-reports". You can specify another location using property "sonar.pitest.reportsDirectory".
Below the exhaustive list of configuration properties of the sonar SonarQubeTM pitest plugin.
Pitest activation mode
Possible values : 'skip', 'active' (not supported yet) and 'reuseReport'
Path to the pitest reports
Path used when mode "reuseReport" is activate to locate pitest xml reports.
|Classes to include in mutation tests||sonar.pit.target.classes||groupId*||The classes to be mutated. This is expressed as a comma seperated list of globs. For example com.mycompany.* or com.mycompany.package.*, com.mycompany.packageB.Foo, com.partner.*. When maven is used, the default value is 'groupId*'|
|Tests to run||sonar.pit.target.tests||sonar.pit.target.classes||A comma seperated list of globs can be supplied to this parameter to limit the tests available to be run. If not specified, the value of "sonar.pit.target.classes" is used (not recommended)|