tdd tutorial

Upload: -

Post on 05-Apr-2018

229 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/31/2019 TDD Tutorial

    1/17

    Test Driven Development

    A Tutorial

    Erik Drnenburg

    ThoughtWorks

    2 Copyright ThoughtWorks, Inc. 2004-2006

    Agenda

    Iteration 0

    Tools for test-driven development

    Iteration 1

    Test-driven development

    Iteration 2

    Interaction-based testing

    Iteration 3

    Lightweight containers

  • 7/31/2019 TDD Tutorial

    2/17

    3 Copyright ThoughtWorks, Inc. 2004-2006

    The four XP values

    Simplicity

    Communication

    Feedback

    Courage

    Iteration 0

    Tools for test-driven development

  • 7/31/2019 TDD Tutorial

    3/17

    5 Copyright ThoughtWorks, Inc. 2004-2006

    Core tools for TDD

    an IDE a unit testing framework

    a build automation tool a continuous integration system

    Iteration 1

    Test-driven development

  • 7/31/2019 TDD Tutorial

    4/17

    7 Copyright ThoughtWorks, Inc. 2004-2006

    Iteration 1

    As a wallet owner I would

    like to be able to put money

    into my wallet so that I can

    take it out later.

    #1

    8 Copyright ThoughtWorks, Inc. 2004-2006

    Iteration 1

    As a wallet owner I would

    like to be able to see howmuch money is in my wallet.

    #2

  • 7/31/2019 TDD Tutorial

    5/17

    9 Copyright ThoughtWorks, Inc. 2004-2006

    Iteration 1

    As a wallet owner I would

    like to be able to take a

    specified amount of money

    out of the wallet.

    #3

    10 Copyright ThoughtWorks, Inc. 2004-2006

    [Switch to development environment]

  • 7/31/2019 TDD Tutorial

    6/17

    11 Copyright ThoughtWorks, Inc. 2004-2006

    Iteration 1

    As a wallet owner I would

    like to be able to take out

    more money than I have, so

    that I can buy things I

    can't afford.

    account#3b

    12 Copyright ThoughtWorks, Inc. 2004-2006

    [Switch to development environment]

  • 7/31/2019 TDD Tutorial

    7/17

    Iteration 2

    Interaction-based testing

    14 Copyright ThoughtWorks, Inc. 2004-2006

    Collaborating Objects

    An object-oriented program is organised as a web ofcollaborating objects

  • 7/31/2019 TDD Tutorial

    8/17

    15 Copyright ThoughtWorks, Inc. 2004-2006

    Using Mocks

    To isolate the tested object we replace its neighbourswith mock objects

    Object under test

    Test case

    Mock

    Mock

    16 Copyright ThoughtWorks, Inc. 2004-2006

    Iteration 2

    As an auditor I would like

    to be notified whenever anaccount is overdrawn.

    #4

  • 7/31/2019 TDD Tutorial

    9/17

    17 Copyright ThoughtWorks, Inc. 2004-2006

    As an auditor I would like

    to be notified whenever an

    account is overdrawn.

    #4

    Iteration 2

    Task 1:

    Introduce AccountService

    #4.1

    18 Copyright ThoughtWorks, Inc. 2004-2006

    As an auditor I would like

    to be notified whenever anaccount is overdrawn.

    #4

    Iteration 2

    Task 2:

    Add audit service and logic

    #4.2

  • 7/31/2019 TDD Tutorial

    10/17

    19 Copyright ThoughtWorks, Inc. 2004-2006

    Iteration 2

    As an account owner I

    would like be notified by

    email when I overdraw my

    account.

    #5

    20 Copyright ThoughtWorks, Inc. 2004-2006

    Iteration 2

    As an auditor I would like

    to be notified whenevermore than 10,000 are

    withdrawn from an account

    in one transaction.

    #6

  • 7/31/2019 TDD Tutorial

    11/17

    21 Copyright ThoughtWorks, Inc. 2004-2006

    [Switch to development environment]

    Iteration 3

    Lightweight containers

  • 7/31/2019 TDD Tutorial

    12/17

    23 Copyright ThoughtWorks, Inc. 2004-2006

    Iteration 3

    Where is my application?

    24 Copyright ThoughtWorks, Inc. 2004-2006

    PicoContainer

    pico containerclasses objects

  • 7/31/2019 TDD Tutorial

    13/17

    25 Copyright ThoughtWorks, Inc. 2004-2006

    [Switch to development environment]

    26 Copyright ThoughtWorks, Inc. 2004-2006

    Iteration 3

    Whats this Inversion of Control

    thing people are talking about?

  • 7/31/2019 TDD Tutorial

    14/17

    27 Copyright ThoughtWorks, Inc. 2004-2006

    Dependency resolution

    Service Locator

    Dependency Injection

    Service Locator

    Dependency Injector

    28 Copyright ThoughtWorks, Inc. 2004-2006

    [Switch to development environment]

  • 7/31/2019 TDD Tutorial

    15/17

    29 Copyright ThoughtWorks, Inc. 2004-2006

    Iteration 3

    But were using theSpring framework!

    Odds and ends

    Object Mother

  • 7/31/2019 TDD Tutorial

    16/17

    31 Copyright ThoughtWorks, Inc. 2004-2006

    Odds and ends

    My tests are ugly!

    32 Copyright ThoughtWorks, Inc. 2004-2006

    [Switch to development environment]

  • 7/31/2019 TDD Tutorial

    17/17

    The end