Search⌘ K

FizzBuzz Kata

Explore the process of applying test-driven development to the FizzBuzz kata using Go. Learn to write tests before code, implement features incrementally, and refactor safely while maintaining test coverage. This lesson builds foundational TDD skills through a practical coding exercise.

We’ll start practicing with the TDD approach. In this group of lessons, we’ll build a kata by following this technique. The example kata we are using is the FizzBuzzkata.
Before starting, let’s review its rules. The FizzBuzz function accepts an integer as a parameter, and it returns a string. The latter depends on the following conditions:

  • If the number is divisible by three, it returns Fizz.
  • If the number is divisible by five, it returns Buzz.
  • If the number is divisible by three and five, it returns FizzBuzz.
  • If the number is neither divisible by three nor by five, it returns a string representation of that number.

In this kata, it’s clear that we have four requirements (or features) to implement. By implementing each of them with the TDD technique, we’ll gain familiarity with this approach and be ready to deal with more complex projects.

The basic

...