January 2020
Intermediate to advanced
640 pages
16h 56m
English
Table-driven tests are a quite compact and rather terse way to efficiently test the behavior of a particular piece of code in a host of different scenarios. The format of a typical table-driven test consists of two distinct parts: the test case definitions and the test-runner code.
To demonstrate this, let's examine a possible implementation of the infamous FizzBuzz test: given a number, N, the FizzBuzz implementation is expected to return Fizz if the number is evenly divisible by 3, Buzz if the number is evenly divisible by 5, FizzBuzz if the number is evenly divisible by both 3 and 5, or the number itself in all other cases. Here is a listing from the Chapter04/table-driven/fizzbuzz.go file, which contains the implementation ...