Testing the tests
Not met yet
A test suite is only as good as the mistakes it would catch. Mutation testing checks it by making small, deliberate mistakes in the code (a < for a <=, a missing check, a wrong number) and running the tests against each one. A broken version that still passes every test has found a gap in the tests. Tests at the edges of each rule, and tests of what should be refused, catch most of these; tests of typical values alone catch few.
Try it
main.pydef real(weight):
return 60 if weight <= 100 else 90
def broken(weight):
return 60 if weight < 100 else 90
def typical(price):
return price(50) == 60 and price(300) == 90
def edge(price):
return price(100) == 60
print(typical(real), typical(broken))
print(edge(real), edge(broken))
Output
Press Run and what your program prints shows up here.
Easy to get wrong
- Thinks testing a few typical values is enough to catch mistakes. Most mistakes sit at the edges of rules, where typical values never go.
- Thinks a passing test proves the code is right, even if the test has never been seen to fail.