Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

Name

Sonar Pitest Plugin

License

LGPL v3

Authors

Alexandre Victoor

Jira

TBD

Sources

http://svn.codehaus.org/sonar-plugins/trunk/pitest

Latest version

-

Download

-

Description / Features

Pitest is a mutation testing tool for java. You can check out the official pitest web site  for more details on mutation testing and pitest. 

Long story short, mutation testing is a very smart way to check the relevance of unit tests. The main idea is to alter the tested code and check that at least one unit test fails. An alteration of the code is called a "mutant". A mutant has "survived" the tests if there is no test failure. 

The goal of this plugin is to bring pitest results to sonar. Right now the integration of these result is quite simple, "survived mutants" on code covered by tests are seen as sonar violations.  

Note : even if pitest detects "survived mutants" on uncovered lines of code, these mutants are simply ignored by the plugin.

Usage & Installation

Sonar server installation 

On the sonar side, just copy the sonar-pitest-plugin jar to the extensions/plugins directory just like any regular sonar plugin. 

Since mutation testing is not (yet) officially supported by sonar, this plugin acts as a "single rule" rule engine... This rule, named "Survived mutant", needs to be activated when pitest is used. 

Project build setup

Right now the plugin does not execute pitest. Pitest needs to be run prior to any sonar analysis using either maven or the command line... You can check out the quickstart section of the official pitest web site for detailed instructions. 

Pitest needs to be configured in order to generate XML reports. The default behavior is to generate HTML reports.  Below a simple configuration example for maven :

inScopeClasses and targetClasses parameters indicated the classes of the system under test where mutations can be performed. In the example from the sonar gallio plugin for C#, all the classes from the org.s.p.c.gallio package and sub packages may be altered. 
Once configured in the maven pom file, you need to run pitest using the following command "mvn org.pitest:pitest-maven:mutationCoverage".
Note : Of course, all the configuration options are clearly explained in the official pitest documentation.

Last but not least, you need to run a sonar analysis with the pitest plugin activated, the following command would do the job :
"mvn sonar:sonar -Dsonar.pitest.mode=reuseReport"

Configuration properties

Below the exhaustive list of configuration properties of the sonar pitest 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 sonar plugin will explore these subfolders and find the newest xml reports generated.

  • No labels