🔗 An example

Say you're building an online casino. Users can only enter the casino when they're over 18. So you write the following piece of code to check if someone is allowed to use the website:

function isUserOldEnough(user) { return user.age >= 18; }

Stryker will find the return statement and decide to change it in several ways:

/* 1 */ return user.age > 18; /* 2 */ return user.age < 18; /* 3 */ return false; /* 4 */ return true;

We call those modifications mutants. After the mutants have been found, they are applied one by one, and your tests are executed against them. If at least one of your tests fail, we say the mutant is killed. That's what we want! If no test fails, it survived. The better your tests, the fewer mutants survive.

Stryker will output the results in various different formats. One of the easiest to read is the clear text reporter:

Mutant killed: /yourPath/yourFile.js: line 10:27 Mutator: BinaryOperator - return user.age >= 18; + return user.age > 18; Mutant survived: /yourPath/yourFile.js: line 10:27 Mutator: RemoveConditionals - return user.age >= 18; + return true;

The clear text reporter will output how exactly your code was modified and which mutator was used. It will then tell us if a mutant was killed, meaning that at least one test failed, or if it survived. The second mutation in this example is marked as a survivor. This means there is probably a test missing that explicitly tests for age lower than 18.