Hacker News new | ask | show | jobs
by schmrz 4638 days ago
I don't know (and don't care) if this makes your unit tests faster, you shouldn't write code like that. He took something that should be simple and made it really complicated. The execution time of your tests shouldn't dictate how you will design and write your application. Especially if it makes things harder to maintain and understand.

Edit: I love tests and they should be fast so that you can run them every time before pushing your changes but as I said they shouldn't dictate how you design and write your application.

2 comments

The point here is not that the tests execution time should dictate the design. On the contrary, the idea of this post was to stress the importance of good design, and that fast tests are just a side effect of it. Now, you might disagree with me on what constitutes good design but that's a different issue.
Don't get me wrong, I agree with the idea that you should look at the root cause of why your tests are slow instead of trying to "fix" the tests. I just feel that what you demonstrated is bad design. So you ended up with bad design and fast tests.
TDD advocates would disagree.
I'm not sure I follow. What exactly would TDD advocates disagree on?
I think he is replying to this:

> ... your tests shouldn't dictate how you will design and write your application

I know that's not your whole quote and a lot of context is lost in that "...", but I think that's what he's replying to.

Pretty much, yes. TDD would say that if testing is painful, changing your design to take away that pain will leave you with a better design overall.