I learned TDD from Pivotal Labs, and it was amazing. It’s totally doable on real non-toy apps, but it is a skill set that takes time to learn and get good at. At first I can feel like drudgery. But once you exercise the muscle enough, you should be able to gracefully go through the red-green-refactor loop again and again in small increments, as I did in this example TDD video using Go.
I’ve worked at something like 20 Bay Area startups (if I include my short-term consulting stints), and I’ve generally experienced that code that lacks adequate testing and becomes buggy failed because people have this mentality that they would start by writing the code then write the tests as an afterthought. But few people actually have the discipline to then break their code to prove that their tests work. So you often see tests that people assume work but actually don’t. The code can break without the test going red. So if you’re going to have to break the code to prove your test works at the end anyway, why not start with a failing test to just skip a step and save time?
It is true that sometimes you don’t have a clear enough idea of how the code will work to even know how the test should be set up. That is a case where the Pivotal Labs guys taught us to write just enough code to be able to write our test, and then comment the code out and test drive it back into existence. There are ways to be in a TDD mindset and still bend the rules a little bit to be pragmatic. But I think a TDD mindset is definitely what you want. It should be your default.
It’s worth acknowledging that Pivotal has established an Extreme Programming (XP) culture in numerous large companies including Boeing, Volkswagen, Dick’s Sporting Goods, Home Depot, Kroger, and so on. XP is includes disciplined pair programming, TDD, continuous delivery, striving for simplicity, etc. And Pivotal honed this suite of practices over two decades, originally working more with startups. There’s a great deal of empirical evidence about the efficacy of TDD and related practices. But again, it is a skill set that has to be learned. You can’t go take one jiu jitsu class and declare, “I tried it in a fight and jiu jitsu didn’t work.”