Test Documentation
Explore how to write precise and informative test documentation for JUnit tests. Understand naming conventions, the benefits of single-purpose tests, and the given-when-then pattern. Learn techniques to make your tests clear and maintainable by improving names, splitting tests, and organizing code for better readability.
Our unit tests should provide lasting and trustworthy documentation of the capabilities of the classes we build.
Tests provide opportunities to explain things that the code itself can’t. In a sense, tests can replace a lot of the comments we might otherwise want to write in the code body.
Follow the naming conventions
Tests follow certain naming conventions which depend on their type.
Combined tests
The more we combine cases into a single test, the more generic and meaningless the test name becomes. A test named “matches” doesn’t tell us anything about ...