TDD
The earlier approach resulted in a code base with some tests. Essentially, Matt wrote the plumbing code to return the simplest possible result (“1,” the result of the parameter 1 passed into FizzBuzz), then wrote the code to make Fizzbuzz “work,” and then wrote tests to check it. That’s better than nothing, but there is no real confidence that the tests cover the important permutations of the software. With Fizzbuzz, the code is trivial. get_total_results
has one loop. You can cover all the code in one test. calc_individual_buzz_result
has three if
statements; you can cover all the code in three tests and all combinations in four.
TDD is a discipline where, before a new line of code is created, the programmer creates a failing test. In our FizzBuzz example, that would mean creating a test for an input of 2
, implementing the code, creating a test for “3” (fizz), implementing the code, creating a test for “5” (buzz...