Make Each Test Unique

The criteria for a good test are that the test fails for a known reason—not any other reason—and that it’s the only test in the system that fails for that reason. In other words, tests should be unique.

When you have unique tests and you don’t have redundant tests, then you get clean feedback when something fails. Typically one test will break, rather than a whole suite of them, and you won’t have to spend weeks trying to clean up those tests.

This is a primary way teams fail when they adopt TDD. They think: Two tests are good, three tests are great, so ten tests must be fantastic. Let’s just write a whole bunch of tests.

But then you end up with test redundancy in the system. When you go to refactor your code, it means ...

Get Beyond Legacy Code now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.