TDD Introduction with Kata FizzBuzz

14
An Introduction to TDD By Example

Transcript of TDD Introduction with Kata FizzBuzz

Page 1: TDD Introduction with Kata FizzBuzz

An Introduction to TDDBy Example

Page 2: TDD Introduction with Kata FizzBuzz

Test Driven Development• Rapid feedback

• Short development cycles

• Incremental design

• Reduced complexity

• Force you to think

• Confidence

Page 3: TDD Introduction with Kata FizzBuzz

Write a Failing

Test

Make the Test

Pass

Refactor

TDD

Red Green Refactor

Page 4: TDD Introduction with Kata FizzBuzz

Principles1. Don’t write any new code until you first have a

failing test.

2. Test everything that could “possibly” break.

3. BabySteps

Page 5: TDD Introduction with Kata FizzBuzz

How to Get to Green• Fake it till you make it

• Fake it - return what the test requires, nothing more

• Obvious - when the code to make the test pass is trivial

• Triangulation - write a second test forcing the ‘fake’ solution to be exposed as insufficient

Page 6: TDD Introduction with Kata FizzBuzz

Refactoring• DRY - Don’t Repeat Yourself

• Technical Debt

• Don’t Live with Broken Windows

• Refactor Early, Refactor Often

Page 7: TDD Introduction with Kata FizzBuzz

Refactoring• Rename variable/method

• Extract variable/method

• Inline variable

Page 8: TDD Introduction with Kata FizzBuzz
Page 10: TDD Introduction with Kata FizzBuzz

The Rules of FizzBuzz• If number is divisible by 3, return “Fizz”

• If number is divisible by 5, return “Buzz”

• If number is divisible by 3 & 5, return “FizzBuzz”

• Otherwise, return the number

Page 11: TDD Introduction with Kata FizzBuzz

Let’s Develop FizzBuzz Kata

Page 12: TDD Introduction with Kata FizzBuzz

Further Reading

Page 13: TDD Introduction with Kata FizzBuzz

Further Reading

Page 14: TDD Introduction with Kata FizzBuzz

Further Reading