Sie sind auf Seite 1von 17

Test Driven Development A Tutorial

Erik Drnenburg ThoughtWorks

Agenda
Iteration 0 Tools for test-driven development Iteration 1 Test-driven development Iteration 2 Interaction-based testing Iteration 3 Lightweight containers
Copyright ThoughtWorks, Inc. 2004-2006

The four XP values

Simplicity Communication Feedback Courage


3

Copyright ThoughtWorks, Inc. 2004-2006

Iteration 0 Tools for test-driven development

Core tools for TDD

an IDE a build automation tool

a unit testing framework a continuous integration system

Copyright ThoughtWorks, Inc. 2004-2006

Iteration 1 Test-driven development

Iteration 1

#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.

Copyright ThoughtWorks, Inc. 2004-2006

Iteration 1

#2

As a wallet owner I would like to be able to see how much money is in my wallet.

Copyright ThoughtWorks, Inc. 2004-2006

Iteration 1

#3

As a wallet owner I would like to be able to take a specified amount of money out of the wallet.

Copyright ThoughtWorks, Inc. 2004-2006

[Switch to development environment]

Copyright ThoughtWorks, Inc. 2004-2006

10

Iteration 1

account 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.

#3b

Copyright ThoughtWorks, Inc. 2004-2006

11

[Switch to development environment]

Copyright ThoughtWorks, Inc. 2004-2006

12

Iteration 2 Interaction-based testing

Collaborating Objects
An object-oriented program is organised as a web of collaborating objects

Copyright ThoughtWorks, Inc. 2004-2006

14

Using Mocks
To isolate the tested object we replace its neighbours with mock objects
Mock

Mock Test case Object under test

Copyright ThoughtWorks, Inc. 2004-2006

15

Iteration 2

#4

As an auditor I would like to be notified whenever an account is overdrawn.

Copyright ThoughtWorks, Inc. 2004-2006

16

Iteration 2

As an auditor I would like Task 1: to be notified whenever an Introduce AccountService account is overdrawn.

#4 #4.1

Copyright ThoughtWorks, Inc. 2004-2006

17

Iteration 2

As an auditor I would like Task 2: to be notified whenever an Add audit service and logic account is overdrawn.

#4 #4.2

Copyright ThoughtWorks, Inc. 2004-2006

18

Iteration 2

#5

As an account owner I would like be notified by email when I overdraw my account.

Copyright ThoughtWorks, Inc. 2004-2006

19

Iteration 2

#6

As an auditor I would like to be notified whenever more than 10,000 are withdrawn from an account in one transaction.

Copyright ThoughtWorks, Inc. 2004-2006

20

[Switch to development environment]

Copyright ThoughtWorks, Inc. 2004-2006

21

Iteration 3 Lightweight containers

Iteration 3

Where is my application?

Copyright ThoughtWorks, Inc. 2004-2006

23

PicoContainer

pico container
classes objects

Copyright ThoughtWorks, Inc. 2004-2006

24

[Switch to development environment]

Copyright ThoughtWorks, Inc. 2004-2006

25

Iteration 3

Whats this Inversion of Control thing people are talking about?

Copyright ThoughtWorks, Inc. 2004-2006

26

Dependency resolution
Service Locator

Service Locator

Dependency Injection

Dependency Injector

Copyright ThoughtWorks, Inc. 2004-2006

27

[Switch to development environment]

Copyright ThoughtWorks, Inc. 2004-2006

28

Iteration 3

But were using the Spring framework!

Copyright ThoughtWorks, Inc. 2004-2006

29

Odds and ends Object Mother

Odds and ends

My tests are ugly!

Copyright ThoughtWorks, Inc. 2004-2006

31

[Switch to development environment]

Copyright ThoughtWorks, Inc. 2004-2006

32

The end

Das könnte Ihnen auch gefallen