You are on page 1of 28

Test Driven Development

A Webinar with Kevin Klinemeier

Kevin Klinemeier
Agile Trainer and Coach Software Developer / Architect / Tester @agilekevin kevin@davisbase.com

Agenda
TDD Overview Expected Values Test Driven Design Additional tools Getting Started

TDD
Spend ~3 days writing tests, then start the real work. Tell your PMO you need more time Fire your QA staff: no manual testing or system needed

Unit Testing
Testing of units, by code
One class or method Very few dependencies

Self-determining no interpretation needed

Categorize the Activity

Red-green-refactor
CreateaTest
Pass

RunaTest
Fail

Failure is success Success is the beginning


Fail

MakeaChange

Change is stability

RuntheTest
Pass

Refactor

Value
Why First? Why in Agile, when we could never justify it before?
Source: Succeeding With Agile: Software Development using Scrum, Mike Cohn

Value

7 Wastes of Software Development


Partially Done Work Extra Features Relearning Handoffs Task Switching Delays Defects
Examples of partially done work: Untested code Uncoded documentation Undocumented code

Tests replace documentation They are TESTS!

7 Wastes of Software Development


Partially Done Work Extra Features Relearning Handoffs Task Switching Delays Defects Only develop code that satisfies the tests. Working sets of tests are a signal to collaborate & review

7 Wastes of Software Development


Partially Done Work Extra Features Relearning Handoffs Task Switching Delays Defects Tests show usage patterns Always up-to-date Facilitates ping-pongpairing

7 Wastes of Software Development


Partially Done Work Extra Features Relearning Handoffs Task Switching Delays Defects Imbedded context dump Small tasks minimize potential for interruption

7 Wastes of Software Development


Partially Done Work Extra Features Relearning Handoffs Task Switching Delays Defects Small tasks increase the frequency of feedback Mocking of external interfaces & dependencies maintains flow

7 Wastes of Software Development


Partially Done Work Extra Features Relearning Handoffs Task Switching Delays Defects Finds bugs early Jump-starts defect resolution to integration layer

Without TDD

Test Last Approach

Test Last - Really

Test Driven Development

Test Driven Design

Test Driven Design


How do we make testing cheaper? Design for testability.
Program to Interfaces Dependency Injection/IOC High Cohesion Low Coupling

Dynamic Mocks
Run-time implementation of interfaces
Example:
We want to test AccountService, but it needs an ICurrencyService. The concrete ICurrencyService needs lots of stuff. The ICurrencyService itself has 50 methods.
mocks = new Mockery(); mockCurrencyService = mocks.NewMock<ICurrencyService>(); accountService = new AccountService(mockCurrencyService); Expect.Once.On(mockCurrencyService). Method("GetConversionRate"). With("GBP", "CAD"). Will(Return.Value(2.20));

Continuous Integration
Scripted Build Integra on Build Machine Transparency & Con nuous Builds Automated Unit Tes ng

CI

Integration Build Machine

Server

Code Coverage
Track progress Target improvements Blame your coworkers

BDD
System Testing, System Integration Testing, and GUI Testing: TDD-style Toolset to parse natural language into automated actions, execute and report results Focuses on business-readable input and output. Maybe even business-writeable. Given (preconditions) When (actor+action) Then (observable result)

Getting Started
Practice Stick with it for at least 3 weeks Dont go it alone Measure progress & gaps with code coverage Expect learning pains

Your Questions
For any questions we arent able to cover, Ill be providing a written response.

Thanks! Kevin Klinemeier @agilekevin kevin@davisbase.com