A Glimpse into TDD

Learning TDD is hard, because programming itself is hard. And the shift of the perspective to write a unit test to make the code fail I believe one of the toughest shift in perspective a developer goes through. And this shift is crucial not with the developer mindset in your team, but in the management as well. Martin Fowler, in this insightful article describes about it, please google for the article.

Advantages-

There are significant advantages one starts noticing and is long preached and measured with TDD practice –

a. Better code coverage

b. Detailed Documentation

c. Fewer bugs in production, its measured almost 40-80% of bug reduction is experienced

d. Better communication across team, and to know more go ahead and read more on it.

Let us jump into solving one of the Code Kata exercises FizzBuzz, by applying TDD. So the idea of FizzBuzz is, if I say 1, you say 1, if I say 2, you say 2, if I say 3, you say Fizz, if I say 4, you say 4, if I say 5, you say Buzz, if I say 6 you say Fizz, and if I say 10 you say Buzz and just in case I say 15 you say FizzBuzz and this continues. So let us say we need to write an application, a simple console app, where if I pass an array of numbers, I get back an array of strings implementing FizzBuzz

Leave a Reply