I recently dipped into TDD while working on an Open Source project - pretty much an unwritten rule that you need tests with an OSS project so contributors understand how everything is implemented.
I’ve been saying it’s like a drug. It slowed down my velocity while adopting it, but overall ended up cutting debugging time in half and brought a lot of possible issues to the foreground much sooner.
I simply just started doing it at my day job. Refactored some of our architecture to allow for dependency injection and started adding tests to classes and objects in the code that I touched. Soon enough during code reviews and other discussions, my fellow team members have started saying “I need to start doing that” and “Can you show me how you might test this?”
The biggest argument and push back I get from developers is the time it will take to start writing tests. And it’s not the fact that it’s more effort. If it’s a legacy project, you’ll almost need to refactor to make the code more testable. So when a defect surfaces, should the team spend 1 week - 1.5 weeks refactoring the code to fix the bug and add tests when the bug can be fixed in an hour two? Most product owners, managers, clients, etc., all say “fix it ASAP!”.
I’ve found once a product owner or manager sees their team function at a particular velocity, dropping below that - even if it’s to add in something like testing - is normally frowned upon.
I’ve started to use this analogy from Uncle Bob Martin: What if you were a doctor and had a patient who demanded that you stop all the silly hand-washing in preparation for a surgery because it was taking too much time? Clearly, you want to listen to the patient, but the doctor should absolutely refuse to comply. Why? Because the doctor knows more than the patient about the risks of disease and infection. It would be unprofessional (never mind criminal) for the doctor to comply with the patient.