3 Elements of TDD
-
Upload
weidagang -
Category
Technology
-
view
754 -
download
6
description
Transcript of 3 Elements of TDD
![Page 1: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/1.jpg)
3 Elements of TDD
Todd Wei
![Page 2: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/2.jpg)
Outline Overview of TDD Test First Development Iterative Incremental Development Refactor
![Page 3: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/3.jpg)
TDD
Pass the test case
RefactorWrite a
failing test case
![Page 4: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/4.jpg)
3 Elements of TDD
TFD
IIDRefactor
![Page 5: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/5.jpg)
Outline Overview of TDD Test First Development Iterative Incremental Development Refactor
![Page 6: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/6.jpg)
Test First Development
Write a Failing Test Case
Pass the Test Case
![Page 7: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/7.jpg)
Why Write Test First? Testability Code Coverage Quick Feedback Simple Design Decoupling Bug Free …
?
Decoupling
Testability
Coverage
![Page 8: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/8.jpg)
Why Write Test First? Testability Code Coverage Quick Feedback Simple Design Decoupling Bug Free …
Specification
Decoupling
Testability
Coverage
![Page 9: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/9.jpg)
Test Case as Specification
“Specification by Example”–Martin Fowler
![Page 10: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/10.jpg)
What’s Specification?
“A specification is an explicit set of requirements to be satisfied by a material, product, or service.” -- Wikipedia
![Page 11: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/11.jpg)
What’s Specification?
User Vendor
Specification
![Page 12: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/12.jpg)
Specification is in Every Level
![Page 13: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/13.jpg)
Where does specification come from?
Requirement
Specification
Requirement Analysis
![Page 14: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/14.jpg)
Test Case as Specification
Requirement
Document
Requirement
Test Case
Traditional
TDD
![Page 15: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/15.jpg)
Software Specification Forms
Specificatio
n
DocumentDesign by ContractTest Case
![Page 16: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/16.jpg)
Document
General
Not Precise
No Feedback
Not Reliable
![Page 17: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/17.jpg)
Design by Contract Contract
Precondition Postcondition Invariant
Precise
Quick Feedback
Abstraction
Limited Functionality
![Page 18: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/18.jpg)
Test Case
Precise
Quick Feedback
User Friendly
Not General
![Page 19: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/19.jpg)
How to Write Good Test Case
Follow requirements
Think of as black box
Construct a scenario
Verify external behavior
![Page 20: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/20.jpg)
Example: Stack
FILO
![Page 21: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/21.jpg)
Bad Test Style
push()
data
pop()
Function/procedure/method and data are the focuses of test
![Page 22: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/22.jpg)
Bad Test Style
![Page 23: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/23.jpg)
Good Test Style
push()
data
pop()
Stack
Feature is the focus of test, e.g. FILO
![Page 24: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/24.jpg)
Good Test Style
![Page 25: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/25.jpg)
Bad vs Good
Bad Good
Behavior
Scenario
Black Box
Requirement
State
Procedure
White Box
Implementation
![Page 26: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/26.jpg)
4 Steps on Writing Good Test Case
Follow requirements
Think of as black box
Construct a scenario
Verify external behavior
![Page 27: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/27.jpg)
Outline Overview of TDD Test First Development Iterative Incremental Development Refactor
![Page 28: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/28.jpg)
Iterative Incremental Development
Pass the test case
Write a failing test
case
TDD = TFD + IID + Refactor
![Page 29: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/29.jpg)
Waterfall
Requirement Analysis
Design
Implementation
TestMaintenance
![Page 30: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/30.jpg)
Waterfall
Phase1
Phase2
Phase3 …
![Page 31: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/31.jpg)
Layer Hierarchy
Business Logic Layer
Presentation Layer
Data Access Layer
![Page 32: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/32.jpg)
Agile: Iterative Incremental Development
Feature1
Feature2
Feature3
…
Feature1.1
Feature1.2
Feature1.3
…
![Page 33: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/33.jpg)
Feature Hierarchy
![Page 34: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/34.jpg)
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
…
![Page 35: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/35.jpg)
Function Cohesion
“Parts of a module are grouped because they all contribute to a single well-defined task of the module” -- Wikipedia
![Page 36: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/36.jpg)
What does unit mean?
Unit vs Atom
![Page 37: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/37.jpg)
What does unit mean?
Hierarchy vs Single Responsibility
![Page 38: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/38.jpg)
What should be tested in unit test?
Do unit test on all levels that can be automated!
![Page 39: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/39.jpg)
Outline Overview of TDD Test First Development Iterative Incremental Development Refactor
![Page 40: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/40.jpg)
TDD
Pass the test case
RefactorWrite a
failing test case
TDD = TFD + IID + Refactor
![Page 41: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/41.jpg)
Software Entropy
Software complexity, change cost increase exponentially as the project goes on
![Page 42: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/42.jpg)
Chaos is not agile
![Page 43: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/43.jpg)
Refactor
Refactoring is a disciplined technique for altering its internal structure without changing its external behavior
![Page 44: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/44.jpg)
Refactor: Bring Order to Chaos
![Page 45: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/45.jpg)
Refactor with TFD
TFD facilitates refactoring and ensure no functionality is broken with regression tests
![Page 46: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/46.jpg)
Refactor with IID
Version1
Version1.1
Version2
Refactor to a stable intermediate version before adding new feature
![Page 47: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/47.jpg)
Summary
Pass the test
case
Refactor
Write a failing test case
TFD
IIDRefactor
![Page 48: 3 Elements of TDD](https://reader033.fdocuments.in/reader033/viewer/2022052504/5494cc0ab47959cb728b46bd/html5/thumbnails/48.jpg)
Question & Answer
Thanks!