Henry
Henry Creator of pitest

Pitest 1.16.2

Pitest 1.16.2

Pitest 1.16.2 has now synced its way through to maven central.

It adds some additional information to the html report, showing the covering tests for each surviving mutant, but also does some new work behind the scenes to allow more code to be mutated.

To explain the change we first need to cover a little background.

Pitest is much faster than the mutation testing systems that came before it, but this required some trade-offs. In exchange for speed pitest has to accept that it mustn’t mutate code that is run only when classes are first loaded.

The most recognisable “on-load-only” code is static initializers, but pitest must also consider enum constructors, code initialising static fields, the call chain originating from each of these and many other cases.

The analysis isn’t 100% perfect, and sometimes pitest will create mutants in code it shouldn’t. When this happens, the mutant might not be killed even when an effective test case exists.

The opposite problem also occurs. While trying to avoid creating unkillable mutants, pitest will sometimes suppress mutants in code it could safely mutate.

Consider the following example

e.g.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public enum AnEnum implements Function<Integer,Integer> {
    ZERO(AnEnum::zero), ADD_TWELVE(AnEnum::addTwelve);

    private final Function<Integer, Integer> action;

    AnEnum(Function<Integer, Integer> action) {
        this.action = action;
    }

    @Override
    public Integer apply(Integer integer) {
        return action.apply(integer);
    }

    private static int zero(int a) {
        return 0;
    }

    private static int addTwelve(int a) {
        return a + 12;
    }

}

The zero and addTwelve methods are referenced only from the constructor of the enum. For a normal method call this would mean the methods executed only when the class was loaded, but in this case only a reference to the method is stored.

The methods will execute each time apply is called, so the code can be safely mutated.

Pitest will now detect a limited number of these scenarios and mark the code as eligible for mutation. The analysis remains imperfect, but better than before.

Thanks for reading. Checkout our industrial quality mutation testing tools for the jvm.