Hacker News new | ask | show | jobs
by AlexandrB 765 days ago
The problem with refactoring test code is twofold:

1. It can make it harder to see what's actually being tested if there are too many layers of abstraction in the test.

2. Complex test code can have significant bugs of its own that can result in false passes. What tests the test code?

Thus I generally see repetitive or copy/pasted test code as a necessary evil a lot of the time.

1 comments

Absolutely this! I was very guilty of over complicating test code to use abtractions and reduce boilerplate, but it certainly resulted in code which you could not always tell what was being tested. And, you'd result in nonsensical tests when the next developer added tests but didn't look deeply to see what the abstractions were doing.

I now find it is best to be very explicit in the individual test code about what the conditions are of that specific test.