Literature defines mutators for general use and specific, designed for certain programing languages. For example, 77 Mutation Operators have been defined for C, Fortran has 22 operators and Java has 29. Below you can find a set of operators, dedicated for Java language.
Mutation operators for Java are divided into two groups. First group is found in the procedural programing languages. Second group consists of operators specific for the object-orientation programing. The following mutation operators were proposed by Yu-Seung Ma, Yong-rae Kwon, and Jeff Offutt – this is important, because you can find more papers, which describe this topic. Furthermore, each Mutation Testing framework implements a different subset of the operators. The following information should illustrate how immense this topic is.
**1. Traditional mutation operators** - based on faults, due to common programming mistakes made in a procedural programing.
![alt text](mtp2_1.jpeg "Traditional mutation operators")
**2. Class related mutation operators** - based on faults due to redeclaration of class variables and a method in corresponding subclass. Because of the abundance of code to present all possible mutants, below are extensive examples only for Java specific operators. In other cases, I have limited myself to a brief description. If you are interested in the details of this topic, please refer to the references at the end.
**2.1. Java specific operators**
![alt text](mtp2_2.jpeg "JDT")
![alt text](mtp2_3.jpeg "JSC")
![alt text](mtp2_4.jpeg "JID")
![alt text](mtp2_5.jpeg "JDC")
![alt text](mtp2_6.jpeg "EOA")
![alt text](mtp2_7.jpeg "EOC")
![alt text](mtp2_8.jpeg "EAM")
![alt text](mtp2_9.jpeg "EMM")
**2.2. Inheritance operators**
![alt text](mtp2_10.jpeg "Inheritance operators")
**2.3. Polymorphism and dynamic binding operators** - based on faults due to Java polymorphism features. Operators check bindings used in a codebase and a possibility to change these bindings with another incorrect one.
![alt text](mtp2_11.jpeg "Polymorphism and dynamic binding operators")
**2.4. Method overloading operators** - based on faults due to method overloading.
![alt text](mtp2_12.jpeg "Method overloading operators")
**Please keep in mind that two similar operators, when applied to a program written in different languages, will most likely produce a different number of mutators.**
## PiTest’s mutators
In this section I will present groups of mutators implemented by PiTest (PIT). The framework is still under the development, and subsequent mutators are in the experimental state. To be up to date, please check the main site of the [project](http://pitest.org/). I also encourage you to analyze the implementation of mutators, available [here](https://github.com/hcoles/pitest/tree/master/pitest/src/main/java/org/pitest/mutationtest/engine/gregor/mutators).
Below you can find PIT’s Mutation Operators groups. You can use names from the left column to configure PIT in your project - we will come back to this later.
![alt text](mtp2_13.jpeg "PIT’s Mutation Operators groups")
## PiTest configuration
In this section, I will show you how you can use PIT together with Intellij, and how to configure PIT’s runner for a better performance. All necessary configuration details are depicted [here](http://pitest.org/quickstart/commandline/).
**1. How to use PIT**
There are a few options - personally I think when you use PIT during the daily development routine, you can minimize costs of Mutation Testing. Because of that I encourage you to utilize PIT plugin dedicated for Intellij.
**1.1. Plugin installation**
You can download the plugin by yourself or directly from Intellij. [Here](https://plugins.jetbrains.com/plugin/7119-pit-mutation-testing-idea-plugin) you can find the PIT’s official site plugin.
**1.2. How to use the PIT plugin**
First, you should setup a default configuration for all PIT’s runners.
![alt text](mtp2_14.jpeg "Default PIT runner configuration")
Now, you can create the configuration runner for your feature. Target classes field points out to an exact package. All tests nested inside a package given by you, will be executed by PIT runner. In case you have declared already other runners, the following shortcut may be helpful: Alt + Shift + F10
![alt text](mtp2_15.jpeg "PIT runner configuration")
**1.3. How to configure Mutation Operators**
By default, PIT uses mutators from DEFAULTS group. In order to use another set of mutators, you should add extra configuration like below. All available names of groups were listed and described at the beginning of the section ‘PiTest’s mutators’.
![alt text](mtp2_16.jpeg "PIT mutators configuration")
**1.4. Other configuration**
You can tune the generation of reports or establish how many threads should be involved into the performing of Mutation tests. All the configuration parameters must be added into Other params field – as in the previous point. [Here](http://pitest.org/quickstart/commandline/) you can find more available PIT’s configuration parameters.
## Mutation testing with other tools
PIT works with the well-known tools like: Maven, Gradle, Eclipse, Junit 5, Spock. At the time when you are reading this article I encourage you to check if PIT supports your favorite tools or programing language – when I started a journey with PIT, I could not find any resources about running PIT with Spock, but when I tried to use it, it turns out that it is possible.
## Be aware!
Mutation testing is time-consuming, because every single mutation requires new build which contains an exact defect. Unfortunately, the number of mutations can easily go into the thousands but luckily, PIT allows us to configure different types of mutators, so we can tune it as needed. Moreover, PIT will try to optimize the tests execution by manipulating a binary code directly or ignore nonconverted code.
Let me summarize what we have learned. First part of the article demonstrates the real-world example of how Mutation Testing can help us. Second part shows what exactly happens under the hood. At the end I demonstrated how to start using PIT plugin. This should be enough to implement Mutation Testing in your projects.
## Resources to learn more
Books & articles
* Aditya P. Mathur – Foundations of Software Testing, 2nd Edition
* Filip van Laenen – Mutation testing. Better code by making bugs
* Adam Goucher, Tim Riley – Beautiful Testing
* Talk in Oxford - Chris Rimmer - [What mutation testing is](http://media.ogn.s3.amazonaws.com/ogn27/microslot-ChrisRimmer.pdf)
* Article in the ACCU magazine Overload - Filip van Laenen’s – [A look at Mutation testing](https://accu.org/var/uploads/journals/overload108.pdf)
* GeeCON 2014 - Gleb Smirnov - [Mutation Analysis](https://vimeo.com/99550776)
* Nicolas Fränkel - [Introduction to Mutation Testing](https://vimeo.com/105758362)
* [PIT’s alternative engine](https://github.com/STAMP-project/pitest-descartes)
* [PIT’s default engine](https://github.com/hcoles/pitest/tree/master/pitest/src/main/java/org/pitest/mutationtest/engine/gregor/mutators)
* [Maven plugin to handle multi module projects for PiTest](https://github.com/STAMP-project/pitmp-maven-plugin)
* [Hints on Test Data Selection Help for the Practicing Programmer](https://www.researchgate.net/publication/2957629_Hints_on_Test_Data_Selection_Help_for_the_Practicing_Programmer)
* [Investigations of the software testing coupling effect](https://www.researchgate.net/publication/2397426_Investigations_of_the_software_testing_coupling_effect)
* [Mutation Analysis](https://www.researchgate.net/publication/235050055_Mutation_Analysis)
* [Mutation testing as quality assurance in base station software](http://liu.diva-portal.org/smash/get/diva2:739835/FULLTEXT01.pdf)
* [MuJava : An Automated Class Mutation System](https://cs.gmu.edu/~offutt/rsrch/papers/mujava.pdf)
* [The Class-Level Mutants of MuJava](https://cs.gmu.edu/~offutt/rsrch/papers/ast-mujava.pdf)
* [Inter-Class Mutation Operators for Java](https://cs.gmu.edu/~offutt/rsrch/papers/javamutop.pdf)