Originally posted by tractor
View Post
TDD doesn't always add value when you're not really sure what you're doing yet. Like when you have a rough idea but you're doing some exploratory tinkering to try to shake out a more complete mental image if what it is you're actually trying to achieve.
TDD generally works at the unit level (a single method up to a small handful of classes working together, encompassing a small unit of functional responsibility). Much of the benefit comes when your unit is more than a single class because design is all about collaboration.
Naive TDD can sometimes lead to a mock/stub obsession - see David Heinemeier Hansson 'TDD is dead' debate with Martin Fowler & Kent Beck. DHH has the wrong end of the stick, and it's not that surprising because as far as I can gather (i'm not expert in rails) rails is inherently very difficult to unit test - and he invented rails.
Beyond tdd similar principles work well at higher levels, with things like ATDD already mentioned, and BDD which focuses on behaviour too, but is really aimed at having a living specification that specifies bahaviour according to inputs and conditions which is understandable to everyone in the business. Works nicely with a domain driven design (DDD) approach and it's idea of a 'ubiquitous language'.
TDD isn't a process that will work well, though, if you follow it blindly. When learning it people suggest literally following the process without much brain input, because it's a disciplin that needs repetition to become a habbit. But beyond learning the basics you need to follow this process of tiny increments followed by refactoring, with mindfulness of good SOLID principles, etc.
You should, though, end up in a situation where every single line of your core domain code has a spcific reason to live - encapsulated in a test that would fail if it didn't. This is a good measure of whether you're doing it properly or not, as when you don't test drive your code (lets assume you write unit tests afterwards) then you can't know this.
Comment