Test Driven Development….it admittedly feels a bit tedious to properly execute. …painful might be a more accurate descriptor.
I am a big picture thinker. I am very good at looking at the end goal and seeing the broad-strokes path to get there. This means that I am most comfortable solving problems in (what I thought were normally-sized) chunks of logic. However, TDD is the opposite of how I am most comfortable approaching problems. TDD requires building a solution in the smallest chunks possible from the ground up. To properly execute it, sometimes you return a fixed value to get a green test rather than do the math. All I can keep thinking is how on earth is typing [return 1] better than [return a+b] when I am going to have to fix it in 3 minutes anyway??
However, despite the pains of execution, I do see that it can be an effective development model when applied in the correct situations.
According to NCrunch, those situations are as follows:
- Pure Logic functions
- A clearly defined set of inputs/outputs
- When defining layers within an application
Likewise, you should AVOID using TDD if….
- Your existing code doesn’t have any tests implemented already
- It is already working
I would also like to add to the list that coding in an exploratory context is not a suitable scenario for TDD. As a student, I often use coding as a medium to work through problems, test different solutions to problems and just explore topics (for example, writing code to draw fractals and messing with it to get a better grasp of how they work). In these types of scenarios, it would be largely a waste of time to take a TDD approach.
Seeing the appropriate times to implement TDD spelled out alleviated a lot of my frustration at the process, as it changed my impression of what TDD was. It was my impression that TDD must be used throughout the entire development process. Although there are some very passionate developers who would live and die by it, I now see it as a tool that can be used when it is needed.
Additionally, I loved the suggestion to look for places to use TDD. Due to my aforementioned gripes with the process, I don’t see myself jumping to implement it on all my projects. However, I do think I would like to integrate it as part of my development process. (i.e. I see a lot of value in implementing TDD to create a particular method that does a complex calculation or that modifies a string.) The guidelines above will serve as an effective starting point in assessing when implementing TDD would be the best path forward.
This blog post was written in response to : https://blog.ncrunch.net/post/when-not-to-use-tdd.aspx
From the blog CS@Worcester – CurrentlyCompiling by currentlycompiling and used with permission of the author. All other rights reserved by the author.