12

Don't reuse your fixtures!

Each test case should be isolated. Don't ever think just because some function requires a similar input, it's safe to reuse it ALL OVER THE PLACE.

Why? Because someday, you want to change one functionality of one unit.

And you adapt your tests, fix your code, and suddenly, by changing one fixture, you break dozens if not hundreds of unrelated tests and now you have to clean up that mess.

It's even worse for functional tests with all those interwoven parts so that it becomes hard to reason about the scope of your tests when lacking proper documentation.

How I know? BECAUSE I AM CLEANING UP YOUR MESS RIGHT NOW!

Comments
  • 2
    @norman70688 It's like a cargo cult. At least clone a base fixture and overwrite the data for each tests to your requirements!
  • 2
    I've long since thought DRY doesn't apply to tests.
  • 0
    @norman70688 Oh, totally. I think styles and rules for test code should be explicitly taught and enforced much more than they are, not just in education but also in tools.
Add Comment