Kashish Singhal
Kashish Singhal

Reputation: 9

Mutation Testing - Reason

Mutation Testing, has a lot of false positives. Despite those false positives, why and when should I use mutation testing?

For eg.

public int add(int a,int b){ 
return a+b; 
}

public void testAdd() {
add(2,2);
...
}

if the mutation results in, return a*b

the test case would still pass, but it should not.

Upvotes: 0

Views: 178

Answers (1)

henry
henry

Reputation: 6096

The example you give is not a false positive (normally referred to as an equivalent mutation)

The mutant would survive as your single test does not fully describe the behaviour you want (addition). i.e mutation testing is telling you that your test suite is deficient.

This should prompt you to add more tests that do describe the behaviour (e.g assert that 1 + 2 = 3).

When you add more tests this mutant will be killed.

You should use mutation testing as your develop to catch your mistakes. Although in theory equivalent mutants represent a big problem (you can only determine if a surviving mutant is equivalent by manually examining it), in practice I've found they are rarely an issue - at least when mutating with pitest.

Upvotes: 2

Related Questions