Mutation Testing

Oli Wennell

Confidence

More than one pair of eyes...

Static analysis...

...

Automated tests

Can we measure test quality?

Yes

Test coverage metrics

But...


validate: function(password) {

    if (password.length > 0 && password.length < 10) {
        return true;
    }

    return false;
}
                    

it('An empty string is not a valid password', function() {
    assert.equal(
        passwordValidation.validate(""),
        false);
});

it('A non-empty string is a valid password', () => {
    assert.equal(
        passwordValidation.validate("A"),
        true);
});
                    

And the test coverage is...

100%!

Remove all assertions?...

100%!

Fettle it

Wouldn't it be nice if...

Mutation Testing


validate: function(password) {

    if (password.length > 0 && password.length < 10) {
        return true;
    }

    return false;
}
                    

The original code


validate: function(password) {

    if (password.length > 0 && password.length <= 10) {
        return true;
    }

    return false;
}
                    

The mutated version

Still from Them! (1954) - http://www.imdb.com/title/tt0047573/

But...

Time

Support

.NET

...and more

Summary

TL;DR

Slides and example code: oliwennell.github.io/


Stryker: stryker-mutator.github.io


Have a chat:

Twitter: @owennell

Email: oliver.wennell@comparethemarket.com