DEV Community

Discussion on: Explain like I'm five: Is Test Driven Development really that used in most of the programming world?

Collapse
 
bertilmuth profile image
Bertil Muth • Edited

There has been a heated debate on whether TDD is good practice or a bad pratice, with valid arguments on both sides (in my opinion).

There is a lot less disagreement whether "Self testing code", as Martin Fowler calls it, is a good thing: martinfowler.com/bliki/SelfTesting...

Spoiler alert: For any non-trivial project, it's a good idea, in my experience. Without it, you can't be sure that you didn't accidentally introduce errors in your software when making changes to the code.

Ever heard of "never change a running system"? That's a sympton of code that is not self testing.

Especially if you are developing in an iterative fashion, regression testing ALL of the code (not just the new features) every iteration is not feasible manually. At least not with reliable results.

But regression testing is exactly what you need to do to prevent unexpected side effects (apart from a design that reduces coupling). A new feature may break an old feature unexpectedly. Or what about that accidental typo you introduced without noticing?

TDD is one practice to lead you to self-testing code.
Some people claim it helps you with the software design, but I would claim you need to know about software design in order for TDD to help you with it.

Collapse
 
imthedeveloper profile image
ImTheDeveloper

I've attempted TDD a few times now in my hobby node.js development projects. I think the biggest thing you find is that when you start a new project you just want to get on and start coding. Pulling in the libraries you need and hacking away through the code.

However, whilst I know I'm a horrible person for doing the above, I do it all too often where time and fun is paramount working on these hobby projects you tend to want to forget the boring test world. With that being said, my current project has hit a point where there's some logic I know I simply need to test. For this specific logic I've produced my test file, added in some cases and I enjoy seeing the code re-run every time I save my work assuring me everything is ok.

There is enjoyment in testing. However, I don't feel like I have the enjoyment in writing a test for every single part of my code. In fact, I know that I struggle with gauging how in depth my scenarios need to be and also how detailed I need to go into the depth of my code to assure myself that everything is working OK. I believe I work in a world where I make a judgement as to how long I'm spending killing myself refactoring, re-running snippets of code and then where an automated test would pay off.

Testing is tough for my mind. As mentioned the level of detail required boggles me and also what about all those scenarios I may invariably miss? I understand the need, I do minimal testing but the world needs to stop making me feel guilty for my lack of 100% coverage.

I'll be posting a new thread soon in the hope to get some answers around some of these questions.