Code Smell 76 — Generic Assertions
Don’t make weak tests to create a false sensation of coverage.
TL;DR: Test Assertions should be precise. Not too Vague and not too specific. There is no silver bullet.
Problems
- False Negatives
- Lack of Trust
Solutions
1. Check the right case
2. Assert for a functional case.
3. Don’t test implementation.
Sample Code
Wrong
Right
Detection
With Mutation Testing techniques we can find these errors on our tests.
Tags
- Testing
Conclusion
We should use development techniques like TDD that request concrete business cases and make concrete assertions based on our domain.
Relations
More info
Credits
This smell was inspired by Mario Cervera and used with his permission.
A program that produces incorrect results twice as fast is infinitely slower.
John Osterhout
This article is part of the CodeSmell Series.