3 ms·
I think the author makes some strong points. It's definitely easy to write bad tests. I think the best defense of unit testing I could make in response to the
by ahepp 3y ago
I think the author makes some strong points. It's definitely easy to write bad tests.
I think the best defense of unit testing I could make in response to the article, is admitting that TDD makes it painful to write tightly coupled code, and that's the point.
If you want to write tightly coupled code (maybe a quick demo of a feature?), or keep the tightly coupled code you already have, don't test it!
The author gets into this a bit, but I'd say the reason they correctly identify testing a UI as painful, is that a lot of UI code is actually data, not behavior. One could argue that enforcing a clear distinction between the two is a benefit of TDD.
- discreteevent 3y ago> TDD makes it painful to write tightly coupled code, and that's the point. That's also the problem with TDD. Another word for "tightly coupled code" is "cohesive code". There's a tradeoff between coupling and cohesion. The problem with TDD is that it can make people decouple cohesive code just to make it testable. I have seen this many times where the only use of some abstraction/indirection was the test. These abstractions/decouplings then mount up to make the codebase much more difficult to understand and maintain than a simple cohesive codebase (with decouplings only where necessary).
- whstl 3y agoI don't completely agree with the assertion that "TDD makes it painful to write tightly coupled code". It really depends on the test tools you have. If you have good mocking tools, and things like test factories, then it becomes quite easy.