Skip to content

The Pitest Framework

brianneoberson edited this page Dec 5, 2023 · 3 revisions

Pitest (formerly known as "PIT") is a widely used open-source mutation testing tool for Java applications. It is highly configurable and provides detailed reports on mutation testing results.

Features of Pitest:

  1. Easy Integration: Pitest can be easily integrated into the Java project using build tools like Maven or Gradle.
  2. Mutation Strategies: Pitest supports various mutation strategies, including replacing method calls with no-ops, changing mathematical operations, and more. This is done by bytecode manipulation which makes it one of the fastest mutation testing frameworks.
  3. Parallel Execution: Pitest can run mutations in parallel, which can significantly speed up the testing process.
  4. Detailed Reports: Pitest generates comprehensive HTML and XML reports that provide insights into the mutation testing results, including mutation score, killed/surviving mutants, and test case information.
  5. Mutation Analysis Thresholds: One can configure Pitest to set mutation analysis thresholds, helping to define what level of mutation score is acceptable for the project.

Installation guide (PIT Gradle plugin)

There are several ways to install Pitest, including as a command line tool line or as a plugin. Since it is generally recommended against installing the command line tool and given that our project uses Gradle as its build system, please refer to the installation guide for the Gradle plugin for PIT by Marcin Zajączkowski: https://gradle-pitest-plugin.solidsoft.info/

How to configure PITest

pitest {
    targetClasses = ['our.base.package.*']  //by default "${project.group}.*"
    pitestVersion = '1.15.0' //not needed when a default PIT version should be used
    threads = 4
    outputFormats = ["XML", "HTML"]
    timestampedReports = false
    //etc.
}

Configurations and parameters available in PITest

See List of PITest parameters here and here

taskClasspath, mutableCodePaths, sourceDirs, reportDir, verbosity and pitestVersion are automatically set by the plugin. sourceDirs, reportDir, verbosity and pitestVersion can be overridden.