Hunt bugs with mutation testing: 12 levels writing tests that catch mutants. A testing game that trains you to think like a tester.
Welcome, Mutant Hunter. Mutation testing is a technique for testing the quality of your test cases. A mutant is a slightly altered version of the code (e.g. + becomes -). A good test must be able to catch every mutant: if a test still passes after the code is mutated, it means the test isn't strong enough.
Boundary testing is a technique for testing at the edge points. If a condition uses >, a test at 0 can tell > apart from >=. This is one of the most effective ways to catch mutants.
A function with multiple branches (if/else) needs a test for every branch. If there are 3 paths, you need at least 3 assertions. This is called branch coverage: every branch must be traversed at least once.
From this level on, some of the value choices are what the mutants return. If your label matches a mutant's result, your test fails on the original function instead. Think: what does the original function output for this input?
Business functions often have guard clauses (input validation). A mutant can change || to &&, which means the validation condition is never true. A test with invalid input is very important for catching mutants in a guard clause.
Memoize stores the result of a computation. A mutant that removes the caching is hard to catch because the output stays the same; the function just gets called again. This shows the limit of mutation testing: not every mutant can be caught with output assertions alone.
> to >=. Pick the assertion that catches it.