Test Your Unit Tests: Mutation Testing
Even if your code coverage is 80%, how much confidence do you have in your unit tests? Are they catching the edge cases? Can you fearlessly refactor? Add new features? Perhaps you are writing code that another team will rely on (or worse, you have to rely on!) Or maybe you have to untangle some ugly spaghetti code and want some idea of what it does before you start chopping it up. A mutation testing framework like PIT from pitest.org tests your JUnit tests and shows you what you are and aren’t testing. If your unit tests all pass, mutation tests make changes to a copy of your source code and rerun the tests to see if they catch the injected errors. If not, the mutation is said to survive, and you know the code isn’t tested, even if code coverage tools suggest otherwise. Gene will show you how to use mutation tests to build confidence in your unit tests. He’ll demonstrate using PIT mutation tests against JUnit tests and show how to use it to turn legacy code into safe-to-refactor Java. Join us if you are struggling to trust your unit tests.