Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: major clean up for new version 0.3

...

Since mutation testing is not (yet) officially supported by SonarQube, 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. 

Project build setup

You have two options in order to produce PIT reports for SonarQube. You can either let the plugin run PIT or you can run PIT prior to the SonarQube analysis.

PIT launched by SonarQube

Warning
There is a compatibility issue with maven 3.X

This is the recommended way to go if your build is based on maven 2. Most mandatory PIT configuration entries will be set using information provided by the pom.xml file of your project. You just need to activate PIT execution and specify which classes to mutate and tests to execute. Below an example:

Code Block
<properties>
  <sonar.pitest.mode>active</sonar.pitest.mode>
  <sonar.pit.target.classes>com.acme.tools.commons*</sonar.pit.target.classes>
  <sonar.pit.target.tests>com.acme.tools.commons*</sonar.pit.target.tests>
</properties>

Note: you will find at the bottom of this page an exhaustive description of all the configuration parameters.

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 needs to be launched before SonarQube

You can launch PIT using the PIT maven plugin or the command line runner. PIT execution must be done before SonarQube analysis. You also need to specify the "reuseReport" mode of the PIT SonarQube plugin. 

...

Name

Key

Default value

Description

Pitest activation mode

sonar.pitest.mode

skip

Possible values : 'skip' , 'active' (not supported yet) and 'reuseReport'

Path to the pitest reports

sonar.pitest.reportsDirectory

target/pit-reports

Path used when mode "reuseReport" is activate to locate pitest xml reports.
Pitest creates a new subfolder "timestamp" at each shot. The SonarQube plugin will explore these subfolders and find the newest xml reports generated.

Classes to include in mutation testssonar.pit.target.classesgroupId*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 runsonar.pit.target.testssonar.pit.target.classesA 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)

Advanced configuration properties

Tip
titleAbout advanced configuration

The properties below mimic the configuration option of the official PIT maven plugin. You can check out the official documentation of this maven plugin to get more detailed information on these options.

...

Name

...

Key

...

Default value

...

Description

...

 

...

Whether to throw error when no mutations found.
Defaults to true.

...

Maximum distance to look from test to class. Relevant when mutating static initializers

...

Calls excluded from mutations

...

sonar.pit.avoid.calls.to

...

major logging framework APIs

...

List of packages and classes which are to be considered outside the scope of mutation

...

Classes not to mutate or run tests from

...

sonar.pit.excluded.classes

...

 

...

List of globs to match against class names. Matching classes will be excluded from mutation. Matching test classes will not be run (note if a suite includes an excluded class, then it will “leak” back in).

...

Not useful when maven is used.
Classpath that contains either JUnit or TestNG as well as your code, tests and any dependencies. When maven is used, this classpath is build using maven classpaths.

You can check out the quickstart section of the official pitest web site for detailed instructions.