We love tests that fail. They indicate problems in our code, usually long before the code is deployed. But the test failure is the first step toward understanding and fixing the bug. Your test code should help you understand what caused the bug.
There are many ways you can do that. If your test follows the earlier principles, the test is cohesive and exercises only one (hopefully small) behavior of the software system. Give your test a name that indicates its intention and the behavior it exercises. Make sure anyone can understand the input values passed to the method under test. If the input values are complex, use good variable names that explain what they are about and code comments in natural language. Finally, make sure the assertions are clear, and explain why a value is expected.
Leave a Reply