Test Driven Development
Jan 16, 2020··
1 min read
Markus Hofbauer
Test Driven Development
Unit Tests
- Separate (non production) program/code to test your code
- Test your code on the lowest (unit) layer
- General 3 step structure of a unit test
- Given: Setup unit and environment
- When: Execute unit to test
- Then: Test for expected result
Why Tests
Michael Feathers, Working Effectively with Legacy Code
“To me, legacy code is simply code without tests.”
TDD
- Write your test before your production code
- 3 Phases
- Red Phase: Define a failing test
- Green Phase: Fix that test (Solve Simple)
- Refactoring: Clean up your code
FizzBuzz Task
Write a function that returns the number it was given or Fizz if it is multiple of 3, Buzz if it is multiple of 5 or FizzBuzz if it is multiple of both.
Task Definition
- Can call function
fizzBuzz
- Return 1 for 1
- Return 2 for 2
- Return Fizz for 3
- Return Buzz for 5
- Return Fizz for 6
- Return Buzz for 10
- Return FizzBuzz for 15