DRY Principal in Tests
I agree with Mark about the DRY (Don’t Repeat Yourself) principal in tests. This is somewhat controversial, so naturally I’ve got something to say.
DRY comes as a solution for maintainability. If code is not duplicated, and sits in one place, then maintaining the code is easier and costs less. No argument here.
In tests, there something else to consider. I am a strong believer in test as a spec. And readability is needed for specs. So this is where test maintainability may clash with readability. I side with readability every time. That’s why I prefer repeating the setup code in the test than putting the common code in a setup method.
Where do you stand on this issue?