Slide 1

Slide 1 text

INTRO TO TDD

Slide 2

Slide 2 text

WHAT IS TDD?

Slide 3

Slide 3 text

TEST DRIVEN DEVELOPMENT

Slide 4

Slide 4 text

"first the developer writes an (initially failing) automated test case that defines a desired improvement or new function, then produces the minimum amount of code to pass that test, and finally refactors the new code to acceptable standards." — Wikipedia

Slide 5

Slide 5 text

1. WRITE A FAILING TEST

Slide 6

Slide 6 text

2. PASS THE TEST

Slide 7

Slide 7 text

3. REFACTOR

Slide 8

Slide 8 text

RED, GREEN, REFACTOR

Slide 9

Slide 9 text

WHY DO TDD?

Slide 10

Slide 10 text

SHORT FEEDBACK CYCLE

Slide 11

Slide 11 text

I COULD DO THIS...

Slide 12

Slide 12 text

OR I COULD DO THIS!

Slide 13

Slide 13 text

SMALLER PIECES

Slide 14

Slide 14 text

"even if I couldn't imagine an implementation I could almost always figure out how to write a test." Kent Beck

Slide 15

Slide 15 text

IMPROVE DESIGN

Slide 16

Slide 16 text

▸ Be a client of your own code. ▸ If it's hard to write the test, rethink your code.

Slide 17

Slide 17 text

REFACTOR WITH CONFIDENCE

Slide 18

Slide 18 text

▸ Stop avoiding old code because you are afraid of breaking it. ▸ Rework becomes enjoyable, not stressful.

Slide 19

Slide 19 text

WHY WRITE THE TESTS FIRST?

Slide 20

Slide 20 text

▸ Demonstrates understanding of what it is we are going to do. ▸ Ensures we are testing the right thing.

Slide 21

Slide 21 text

LET'S GET STARTED!

Slide 22

Slide 22 text

There should be a method on Calculator called "add" that takes a string representation of a number ("1") and returns it as a number (1).

Slide 23

Slide 23 text

When I give the method an empty string (""), it should return 0.

Slide 24

Slide 24 text

require "minitest/autorun" require_relative "calculator" class TestCalculator < MiniTest::Unit::TestCase def test_given_string1_returns_1 assert_equal Calculator.add("1"), 1 end def test_given_string_returns_number number = rand(100) assert_equal Calculator.add(number.to_s), number end end

Slide 25

Slide 25 text

class Calculator def self.add(string) string.to_i end end

Slide 26

Slide 26 text

YOUR TURN!

Slide 27

Slide 27 text

SHARE YOUR SOLUTION!

Slide 28

Slide 28 text

FURTHER READING ▸ Test Driven Development on Wikipedia ▸ The Three Rules of TDD by Uncle Bob ▸ Test Driven Development from The Art of Agile Development ▸ Extreme Programming ▸ Test Driven Development By Example ▸ String Calculator Solution by ericroberts