Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Intro to TDD

Intro to TDD

This presentation was written in Markdown and presented with Deckset. There are gifs as part of the presentation but they don't translate well to PDF. You can find the original markdown file here: https://github.com/Boltmade/intro-to-tdd/blob/master/presentation.md

Eric Roberts

April 17, 2015
Tweet

More Decks by Eric Roberts

Other Decks in Programming

Transcript

  1. "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
  2. "even if I couldn't imagine an implementation I could almost

    always figure out how to write a test." Kent Beck
  3. ▸ Be a client of your own code. ▸ If

    it's hard to write the test, rethink your code.
  4. ▸ Stop avoiding old code because you are afraid of

    breaking it. ▸ Rework becomes enjoyable, not stressful.
  5. ▸ Demonstrates understanding of what it is we are going

    to do. ▸ Ensures we are testing the right thing.
  6. 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).
  7. 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
  8. 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