3 elements of tdd
DESCRIPTION
Agile Tour 2010 Chengdu presentationTRANSCRIPT
3 Elements of TDD
Todd Wei
Outline Overview of TDD Test First Development Iterative Incremental Development Refactor
TDD
Pass the test case
RefactorWrite a
failing test case
3 Elements of TDD
TFD
IIDRefactor
Outline Overview of TDD Test First Development Iterative Incremental Development Refactor
Test First Development
Write a Failing Test Case
Pass the Test Case
Why Write Test First? Testability Code Coverage Quick Feedback Simple Design Decoupling Bug Free …
?
Decoupling
Testability
Coverage
Why Write Test First? Testability Code Coverage Quick Feedback Simple Design Decoupling Bug Free …
Specification
Decoupling
Testability
Coverage
Test Case as Specification
“Specification by Example”–Martin Fowler
What’s Specification?
“A specification is an explicit set of requirements to be satisfied by a material, product, or service.” -- Wikipedia
What’s Specification?
User Vendor
Specification
Specification is in Every Level
Where does specification come from?
Requirement
Specification
Requirement Analysis
Test Case as Specification
Requirement
Document
Requirement
Test Case
Traditional
TDD
Software Specification Forms
Specificatio
n
DocumentDesign by ContractTest Case
Document
General
Not Precise
No Feedback
Not Reliable
Design by Contract Contract
Precondition Postcondition Invariant
Precise
Quick Feedback
Abstraction
Limited Functionality
Test Case
Precise
Quick Feedback
User Friendly
Not General
How to Write Good Test Case
Follow requirements
Think of as black box
Construct a scenario
Verify external behavior
Example: Stack
FILO
Bad Test Style
push()
data
pop()
Function/procedure/method and data are the focuses of test
Bad Test Style
Good Test Style
push()
data
pop()
Stack
Feature is the focus of test, e.g. FILO
Good Test Style
Bad vs Good
Bad Good
Behavior
Scenario
Black Box
Requirement
State
Procedure
White Box
Implementation
4 Steps on Writing Good Test Case
Follow requirements
Think of as black box
Construct a scenario
Verify external behavior
Outline Overview of TDD Test First Development Iterative Incremental Development Refactor
Iterative Incremental Development
Pass the test case
Write a failing test
case
TDD = TFD + IID + Refactor
Waterfall
Requirement Analysis
Design
Implementation
TestMaintenance
Waterfall
Phase1
Phase2
Phase3 …
Layer Hierarchy
Business Logic Layer
Presentation Layer
Data Access Layer
Agile: Iterative Incremental Development
Feature1
Feature2
Feature3
…
Feature1.1
Feature1.2
Feature1.3
…
Feature Hierarchy
Example: multi-dimensional objectName Project Expertise Degree Gender
Allen Project1 Develop Master Male
Rebecca Project1 Test Bachelor Female
Kay Project2 Develop Bachelor Female
David Project2 Test Master Male
… … … … …
Company
Develop
Project1
Project2
Test
…
Company
Project1
Develop Test
Project2
…
Function Cohesion
“Parts of a module are grouped because they all contribute to a single well-defined task of the module” -- Wikipedia
What does unit mean?
Unit vs Atom
What does unit mean?
Hierarchy vs Single Responsibility
What should be tested in unit test?
Do unit test on all levels that can be automated!
Outline Overview of TDD Test First Development Iterative Incremental Development Refactor
TDD
Pass the test case
RefactorWrite a
failing test case
TDD = TFD + IID + Refactor
Software Entropy
Software complexity, change cost increase exponentially as the project goes on
Chaos is not agile
Refactor
Refactoring is a disciplined technique for altering its internal structure without changing its external behavior
Refactor: Bring Order to Chaos
Refactor with TFD
TFD facilitates refactoring and ensure no functionality is broken with regression tests
Refactor with IID
Version1
Version1.1
Version2
Refactor to a stable intermediate version before adding new feature
Summary
Pass the test
case
Refactor
Write a failing test case
TFD
IIDRefactor
Question & Answer
Thanks!