Mark Robinson
That's QA's problem
I do TDD, I know my tests are good
Pull requests enforce test quality
We measure code coverage
This code was executed as part of a test
This code was not executed as part of a test
public class CalculatorTest() {
@Test
public void seniorEngineerSaysMustHaveTestCoverage() {
int result = Calculator.add(5, 2);
}
}
public class Calculator() {
public static int add(int first, int second) {
return first + second;
}
}
"Fault diagnosis of computer programs"
1) Introduce a bug!
2) See if the test suite fails
public void countIfGreaterThanNine(int number) {
if (number > 10) {
count++;
}
}
Survived
Killed
Test Suite Fails
Test Suite Passes
Killing is good!
Programmers are generally competent enough to produce code which is at least almost correct
Tests that can distinguish a program differing from a correct one by only simple errors can also implicitly distinguish more complex errors
1
public void someFunction(int i) {
if (i <= 100) {
throw new IllegalArgumentException();
}
if (i == 100) { // changed from >= to ==
doSomething();
}
}
public void someFunction(int i) {
if (i <= 100) {
throw new IllegalArgumentException();
}
if (i == 100) { // changed from >= to ==
doSomething();
}
}
public void someFunction(int i) {
if (i <= 100) {
throw new IllegalArgumentException();
}
doSomething();
}
public void someFunction(int i) {
if (i <= 100) {
throw new IllegalArgumentException();
}
if (i >= 100) {
doSomething();
}
}
...mutation testing with productive mutants does not add a significant overhead to the software development process...
1
|
Based on testing at Google
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>1.4.1</version>
</plugin>
Tips
mvn clean install org.pitest:pitest-maven:mutationCoverage