An Introduction To Test-Driven Development (TDD)
An Introduction To Test-Driven Development (TDD)
An Introduction To Test-Driven Development (TDD)
Agenda
5 minutes
30 minutes
1.
What is TDD?
2.
TDD Stages
3.
4.
Why TDD?
What is TDD?
An indication of intent
Tests provide a specification of what a piece of code actually
does
Some might argue that tests are part of the documentation
TDD Stages
Write a test
Refactor code
(and test)
Compile
Run test,
watch it pass
Write code
Run test,
watch it fail
Before TDD
After TDD
ID: US18898
Name: Remove Recurring Flag in the agreement
screens in Siebel
Description:
As a GCSO Rep, I want to see clean and accurate
contract data in Siebel, so I can perform my work
correctly, Since the Recurring Flag is being "retired" in
favor of other contract characteristics like Contract
Term, Billing Behavior and Renewal Term / UOM, the
Agreement Recurring Flag should be removed from all
Siebel UI's where it is displayed.
ID: US18898
Name: Remove Recurring Flag in the agreement
screens in Siebel
Acceptance test:
The system will display clean, accurate contract data
in Siebel:
Contracts pulled down
Contract Details in header
Description:
As a GCSO Rep, I want to see clean and accurate
contract data in Siebel, so I can perform my work
correctly, Since the Recurring Flag is being "retired" in
favor of other contract characteristics like Contract
Term, Billing Behavior and Renewal Term / UOM, the
Agreement Recurring Flag should be removed from all
Siebel UI's where it is displayed.
Bob Martin:
Confidence boost
2.
3.
5.
Summary
Project Management
Communications
Key messages and key themes inform, engage and promote sustained change.
Training
TDD is a new behavior. It is key to define and provide your team with helpful
resources such as quick reference guides, demos, and coaching.
You know your team culture best. Dont go by the book on TDD methods. If
your teams get engaged by using a buddy system, or learn better by getting
outside, sponsor an event to get them moving.
10
2.
3.
4.
Embrace learning
5.
Avoid isolation
11
An Introduction to
Behaviour Driven Development
(BDD)
BDD is:
Behavior driven
How do you write a test when you dont know where you are going?
Requirements
What are they
Audience is typically the stake holders and not the development team
Can be tested!!!
Are attainable!!!
Requirements gathering
BDD merges two different approaches
User Stories
Short one or two line statement that maps to a few days of development work
Highly focused
Story Template
As a [User/Role]
I want [Behaviour]
so that [I receive benefit]
Example
As a Operations staff member
I want To create a Portfolio
so that So that it can be traded
NBehave
What is it?
Test runner that executes the stories and generates a report listing the contents of the stories
BSD License
Creating a Story
Fluent interface to define the story
Creating a Scenario
Fluent interface to define the story
Use Pending
story.WithScenario("portfolio does not exist")
.Pending("In progress")
.Given("portfolio name is $name", "Aggressive Fund")
.When("portfolio does not exist in the database")
.Then("new portfolio should be created");
1.
2.
3.
4.
5.
Story
Pending Scenario
Stubbed Behavior Cycle (Red, Green, Refactor)
Real Behavior Cycle (Red, Green, Refactor)
Acceptance Test
Story
Pending
Scenario
Stubbed
Scenario
Real
Behaviour
Acceptance
Test
ItemExistsException());
Stubbing example
Create a new portfolio story
TFD/BDD Comparison
Test First
Behavior Driven
Bottom Up approach
Lots of little steps working towards a
solution
Output
Tests
Output
API creation
Giving it a go
Adding NBehave to your team
Developer Driven
Peer programming One person writes the scenario the other person removes
Pending() and makes it green
Consider not using NBehave story runner and host Stories within current
Continuous Integration setup (Use NUnit Test Fixture as opposed to Theme)
Giving it a go
Adding NBehave to your team
continued...
Use NBehave story output as a deliverable to analysis/test team ie as part of the release
notes
More information
http://nbehave.org/
http://www.codeplex.com/NBehave
http://behaviour-driven.org/
http://dannorth.net/
Questions?