Bad Practices of Testing
Presentation showing bad test code and how to improve it.
All examples come from real commercial projects and caused development team smaller or bigger problems.
No code has been taken from these projects. All code shown has been written from scratch using completely different (made-up) domain in order to show only the smallest necessary snippet of code.
Table of contents
- Meaningless tests names
- Using JUnit Parameterized
- Logic in the test
- Test's expectations set up in production code
- Dependencies between tests
- Non thread-safe unit tests
- Multiple assert statements to verify a list
- Fake not meeting the contract of the interface it is implementing
- Testing implementation instead of behaviour
- Asserting on exception's message
- Swallowing assertion error
- Mocking data objects
- Testing what the code does not do
- Asserting on default value
- Non distinct test data
- JMock verifying method was called
- Fluent assertions (AssertJ)