4 ms·
When writing tests is boring, difficult, and tedious, that's a really good time to think hard about the way the program is structured, if you have time for this
by mbrock 11y ago
When writing tests is boring, difficult, and tedious, that's a really good time to think hard about the way the program is structured, if you have time for this.
The way to make testing pleasant is to extract more and more behavior into units with clear boundaries... realizing how to do this was a major event in my programming career, and I attribute the insight partly to doing TDD.
I don't agree with some posters who say that TDD encourages overly generalized design. Sure, it encourages some form of dependency injection... but mostly, it just encourages the creation of coherent and loosely coupled units, which is a universally lauded best practice.
- jamestenglish 11y agoWhen I finally decided to really decouple and mock dependencies and create "pure" unit tests was the major "Ah ha!" moment of TDD. I had been trying it out here and there but never really saw the benefit because I wasn't really creating nice testable units. It is hard to say for sure, because the author doesn't give any specifics but wording like: "You therefore are more reluctant to make large-scale changes that will lead to the failure of lots of tests. Psychologically, you become conservative to avoid breaking lots of tests." make me think the author wasn't actually making unit tests, instead they were likely end-to-end tests, or partial ETE tests that were running inside a unit test framework. I have had many disagreements with other developers that just because your test runs inside a unit testing framework doesn't actually make your test a "unit" test.
- Chris2048 11y agoIf you move functionality around between methods, or combining, breaking up methods, won't that mean fixing all those unit tests?
- mbrock 11y agoSure, and that fixing is the process of making sure that the code still works, and that you still have the test suite as a second client of the code. As with everything there are costs and benefits! A lot also depends on the quality of your tests. If the team doesn't care about test quality or doesn't know how to write good tests, you can easily get these big blobs of incomprehensible and tedious tests...
- jon-wood 11y agoIt encourages dependency injection, which in my experience will eventually encourage a functional programming style since there's so little barrier to it once you're doing things like injecting the current time into a method which makes use of it. Maybe I'll turn around in five year's time and regret saying this, but I've never regretted pushing a project in a functional direction.
- Chris2048 11y agoSurely the value of functional style depends on language. Some languages have better guarantees that support functional styles.