21 Testing Mistakes - Part 4
16. Ignoring mutation testing and not verifying if the tests are covering all cases
17. Creating objects in every test instead of having object mothers
18. Not using explicit data structures in tests, but referencing previously created ones
19. Not caring about test code quality
20. Always adding tests into only one file
21. Ignoring test automation in the CI process
16. Ignoring mutation testing and not verifying if the tests are covering all cases
Sometimes when writing complex code, you want to make sure your tests cover every case. To do that, you follow the logic and verify that a test for this exists. This is good, but there is one additional thing you can do to make sure everything is tested: Mutation Testing.
To perform Mutation Testing, all you need to do, is comment out some line or change some condition and then run your tests. If some test fails, then that logic / condition is tested. If everything passes, then it probably means that a test is missing for that chunk of code.
Of course, don't go over board with this and check every line, you should probably focus on parts:
- That you're not sure are tested correctly
- Complex logic that is hard to follow
- Really important parts of the system
Applying Mutation testing will give you more confidence, that the SUT is correctly tested and that any regression will be caught by your Automated test suite.
17. Creating objects in every test instead of having object mothers
This topic is point borrows from the helper functions section. Basically, instead of repeating the same instantiation / creation logic every time, you could create a helper function which creates it for you.