152
ATDD Acceptance Test Driven Development Jared Richardson Agile Artisans @JaredRichardson 1

Atdd half day_new_1_up

Embed Size (px)

Citation preview

Page 1: Atdd half day_new_1_up

ATDDAcceptanceTest Driven Development

J a r e d R i c h a r d s o n A g i l e A r t i s a n s

@ J a r e d R i c h a r d s o n

1

Page 2: Atdd half day_new_1_up

Who are you?

2

Page 3: Atdd half day_new_1_up

Jared RichardsonCoAuthored GROWS Methodology

Author Ship It! and Career 2.0

Screencast editor PragProg.com

2nd public signatory of the Agile Manifesto

Started AgileRTP in 2007!

Coach

AgileArtisans.com

3

Page 4: Atdd half day_new_1_up

Who are you?

4

Page 5: Atdd half day_new_1_up

What would you say you do here?

Roles?

Responsibilities?

Why are you here?

What are your tests for this session?

5

Page 6: Atdd half day_new_1_up

ObjectivesDefine ATDD

Why requirements are not enough

Who to involve when

Turning requirements into tests

What to test

How ATDD can make your entire company more productive

6

Page 7: Atdd half day_new_1_up

Outline

Terms and definitions

Requirements and tests

Software development

ATDD examples

Anatomy of a test

Tables (Grid Driven Development)

7

Page 8: Atdd half day_new_1_up

Take Aways

What’s a test?

Who writes them?

When are they written?

What do they verify?

Provide an example

Primary benefit?

Secondary benefits?

8

Page 9: Atdd half day_new_1_up

Breaks

Halfway (90 minutes)

9

Page 10: Atdd half day_new_1_up

Background

Lean-Agile Acceptance Test Driven Development

by Ken Pugh

10

Page 11: Atdd half day_new_1_up

One Rule

There are exceptions to every statement

Except this one

11

Page 12: Atdd half day_new_1_up

Start

Familiar

Working

Smooth

Teaching

Dreyfus ModelofSkillsAcquisition

en.wikipedia.org/wiki/Dreyfus_model_of_skill_acquisition

12

Page 13: Atdd half day_new_1_up

Start

Familiar

Working

Smooth

Teaching

Dreyfus ModelofSkillsAcquisition

Steps

Recipes

Intuition

Stuck

Principles

13

Page 14: Atdd half day_new_1_up

Key Points

Skills don’t map

dilbert.com/strip/1990-09-13

14

Page 15: Atdd half day_new_1_up

Key Points

Beginners need steps

15

Page 16: Atdd half day_new_1_up

What is ATDD?

Acceptance Test Driven Development

External view of the system

Examines visible effects

Inputs

Outputs

State changes

External interfaces16

Page 17: Atdd half day_new_1_up

Definitions

Acceptance criteria -> General idea

Acceptance test -> specific. Pass/fail.

Implementation independent

Triad -> Customer, developer, tester

17

Page 18: Atdd half day_new_1_up

Fast Car

Who wants one?

Criteria

Closed course. Measure acceleration.

Test

Accelerate 0 to 60 in X seconds

flickr.com/photos/vodcars/4132650949

18

Page 19: Atdd half day_new_1_up

Fast Car

flickr.com/photos/fordeu/14296246942

0 to 60 in 30 seconds

0 to 60 in 5 seconds.

Top speed is 61.

0 to 60 in 5. Top speed is 120.

60 to 120 in 5 min

0 to 60 in 5. 60 to 120 in 20 sec.

Range of 1/4 mile.

19

Page 20: Atdd half day_new_1_up

0 to 60 in 30 seconds

0 to 60 in 5 seconds.

Top speed is 61.

0 to 60 in 5. Top speed is 120.

60 to 120 in 5 min

0 to 60 in 5. 60 to 120 in 20 sec.

Range of 1/4 mile.

Range of 1,000 miles. Cost 7 billion

Fast Car

flickr.com/photos/alpi-costerni/8161111001

20

Page 21: Atdd half day_new_1_up

Why ATDD?Rework down from 60% to 20%

Workflows work 1st time

Little room miscommunication

Saves time

Getting business rules RIGHT

Tighter cross functional team integration

Crisp visible story completion criteria

Automation yields reduced testing time21

Page 22: Atdd half day_new_1_up

Requirements and Tests

22

Page 23: Atdd half day_new_1_up

Requirement

Needed by a user to solve a problem

Needed by a system to satisfy contract, standard, spec, regulation...

23

Page 24: Atdd half day_new_1_up

Requirements Include

Functions (what software does)

Constraints (limits)

24

Page 25: Atdd half day_new_1_up

Requirements Should not

Include

Implementation details

Specific manifestation

25

Page 26: Atdd half day_new_1_up

A Brownie Spec

Ingredient Parts by weight

Sugar 23.0Flour 21.0Shortening 16.8 Nuts 16.0whole eggs 13.0Cocoa 5.5Dextrose, anhydrous 4.4Salt

26

Page 27: Atdd half day_new_1_up

Brownie Spec

a. Whip eggs in large bowl on high speed until light and fluffy.b. Combine sugars, cocoa, salt, and leavening; add to beaten eggs, and whip on high speed until thick.c. Add shortening slowly while mixing on low speed.d. Scrape bowl and whip on high speed until thick.e. Mix flour, nuts, and flavors together and fold into batter; mix until uniform.f. Pour batter into pan at a rate that will yield uncoated brownies which, when cut such as to meet the dimension requirements specified in 3.4f, will weigh approximately 35 grams each. g. Bake at 3500F until done (45 minutes).h. Cut into 2 inch squares

27

Page 28: Atdd half day_new_1_up

Requirements and tests

Inter-related

Can't have one w/o the other

Failing test is a requirement

Passing test valid system spec

28

Page 29: Atdd half day_new_1_up

ATDD as a Prism

Requirements

Tests

ATDD

29

Page 30: Atdd half day_new_1_up

Software Development

30

Page 31: Atdd half day_new_1_up

Exercise What Issues?

Current software dev process

Write down your org’s issues

Groups of 3 to 8

Pass to front

31

Page 32: Atdd half day_new_1_up

Developers Testers

Customers

The Team

32

Page 33: Atdd half day_new_1_up

Customer Unit

Product owner

Business analysts

Users

QA

33

Page 34: Atdd half day_new_1_up

Developer/Tester Unit

Programmers

Testers

QA

34

Page 35: Atdd half day_new_1_up

Developers Testers

Customers

The Triad

35

Page 36: Atdd half day_new_1_up

Traditional Value Stream

Elicit&Requirements&

Analyze&Requirements& Design&&

Code& Test&

Why go back?

Deploy&

36

Page 37: Atdd half day_new_1_up

Requirements

Write Code

The Traditional Approach

Demo

Rewrite

“Discussion”

Typically a confrontation &

argument

The demo forces a discussion of the

requirementsAn isolated event,

primarily worked by the customer proxy

37

Page 38: Atdd half day_new_1_up

Demo

Write Code

Requirements

The Agile Approach

Rewrite

Before significant time and $$ is

invested

Discuss

Include the Golden Triad

Dev QA

Customer38

Page 39: Atdd half day_new_1_up

Mistakes?

Misunderstandings

Missed requirements

Mis other

39

Page 40: Atdd half day_new_1_up

Mistakes

Feedback corrects misunderstandings

Quick feedback is better than slow feedback

40

Page 41: Atdd half day_new_1_up

Desired Actual

Slow Feedback

Actual

Fast Feedback

41

Page 42: Atdd half day_new_1_up

Agile Value Stream

Elicit&Requirements&

Analyze&Requirements&With&Tests&

Design&&

Code&With&Tests& Deploy&

42

Page 43: Atdd half day_new_1_up

Move Testing Forward

43

Page 44: Atdd half day_new_1_up

Two Types of Testing

To find defects

To prevent defects

44

Page 45: Atdd half day_new_1_up

Finding Defects

Waste

Identifying mistakes

flickr.com/photos/mag3737/444557606

45

Page 46: Atdd half day_new_1_up

preventing Defects

Saves development time

Saves QA time

Saves money

46

Page 47: Atdd half day_new_1_up

Steps

Author tests (write)

customer, tester, developer together

Connect to the system (automate)

developer

Run the tests (execute)

developer, testers, customers, CI system

Test% write% bind% run%

47

Page 48: Atdd half day_new_1_up

Two Ways

Code%write% run%bind%

Code%write%

run%

bind%

48

Page 49: Atdd half day_new_1_up

Test First

Write the test first

Write the code after

One molds the other

First in wins

49

Page 50: Atdd half day_new_1_up

Testing Strategies

Meszaros, XUNIT TEST PATTERNS: REFACTORING TEST CODE, Fig 6.1 "Purpose of Tests" p. 51, © 2007 Pearson Education, Inc

50

Page 51: Atdd half day_new_1_up

Testing Focus

51

Page 52: Atdd half day_new_1_up

Verification vs

ValidationVerification Are the requirements right Focus of acceptance tests

Validation Have we got the right requirements? Customer really do it this way? How do you test this?

52

Page 53: Atdd half day_new_1_up

Where to test?

53

Page 54: Atdd half day_new_1_up

Acceptance Testing

Applica'on*/**Middle*'er*

Core*Business*Logic**

UI*

Persistence*

Acceptance Tests

54

Page 55: Atdd half day_new_1_up

Tests all the way down

Requirement* Requirement**

Test* Test*

Requirement*

Test*

Test*

Service*Implementa4on*

Test*

Customer Acceptance Tests

Developer Acceptance Tests

Service*Implementa4on*

Requires services to implement

55

Page 56: Atdd half day_new_1_up

Acceptance Test Examples

56

Page 57: Atdd half day_new_1_up

Temperature

Input in Celsius

Output in Fahrenheit

How long to code?

57

Page 58: Atdd half day_new_1_up

Temperature

F = C x 9/5 + 32

58

Page 59: Atdd half day_new_1_up

Temperature

Tests?

59

Page 60: Atdd half day_new_1_up

Temperature

60

Page 61: Atdd half day_new_1_up

Test Binning

Celsius' Fahrenheit' Notes'0" 32"100" 212" Needed?"

Celsius' Fahrenheit' Notes'*273.15" *459.67" Precision"

Formula Tests

Precision Tests

Celsius' Fahrenheit' Notes'*273.15" *459.67" 0"Kelvin""*273.151" Error" Below"0"Kelvin""500" 932" Maximum"–"Needed?"

Limit Tests

61

Page 62: Atdd half day_new_1_up

Temperature

Input in Celsius

Output in Fahrenheit

How long to code?

62

Page 63: Atdd half day_new_1_up

Is This A Good Spec?

63

Page 64: Atdd half day_new_1_up

Business Rules

If a Customer Rating is Good and the Order Total is less than or equal $10.00, Then give no discount Otherwise give a 1% discount

If Customer Rating is Excellent, Then give a discount of 1% for any order

If the Order Total is greater than $50.00, Then give a discount of 5%

64

Page 65: Atdd half day_new_1_up

Rule Table => Test

?

?

65

Page 66: Atdd half day_new_1_up

Another Business Rule

Email coupon codes

If a customer enters the code, provide a 20% discount

Discount an item or the order?

66

Page 67: Atdd half day_new_1_up

Implementation

Testing script

Program interface

Xunit framework

ATDD framework

67

Page 68: Atdd half day_new_1_up

Testing Script

Tools for testers

(Usually) GUI based

68

Page 69: Atdd half day_new_1_up

Testing Script

Log in as a Customer who is rated GoodStart an OrderAdd items totally $10.01Complete order Verify $0.10 discount

Repeat for 10 other similar cases

69

Page 70: Atdd half day_new_1_up

Program Interface

Code something (CLI or GUI)

Screen

Discount Method

Discount Percentage Screen Customer Type: Good Order Total: 10.01 Percentage: 1 %

C:>DiscountPercentage Good 10.01 Percentage: 1%

70

Page 71: Atdd half day_new_1_up

Xunit Test

class TestCase { testDiscountPercentageForCustomer() { SomeClass o = new SomeClass()

assertEquals(0, o.computeDiscount(10.0, Good)); assertEquals(1, o.computeDiscount(10.01, Good)); assertEquals(1, o.computeDiscount(50.01, Good)); assertEquals(1, o.computeDiscount(.01, Excellent)); assertEquals(1, o.computeDiscount(50.0, Excellent));

assertEquals(5, o.computeDiscount(50.01, Excellent));

} }

71

Page 72: Atdd half day_new_1_up

Fit Test

72

Page 73: Atdd half day_new_1_up

Tables as Requirements and Tests

Discount Rule Customer Rating Order Total Discount Percentage

Good <= $10.00 0% Otherwise 1%

Excellent Any 1% > $50.00 5%

Discount))Test)Order)total) Customer)ra3ng) Discount)percentage?)$10.00% Good% 0%%$10.01% Good% 1%%$50.01% Good% 1%%$.01% Excellent% 1%%$50.00% Excellent% 1%%$50.01% Excellent% 5%%

Requirement

Test

73

Page 74: Atdd half day_new_1_up

Context

74

Page 75: Atdd half day_new_1_up

Context Diagram

Process'

User

Reports

Commands Views

75

Page 76: Atdd half day_new_1_up

Another Context Diagram

Process'

User

Another System Shared Database

Commands

Views

Requests

Responses

Stores

Retrievals

76

Page 77: Atdd half day_new_1_up

Engine Controller

Engine&Controller&

Engine Rotation Speed

Gasoline Flow Control

Spark Timing

Acceleration / De-acceleration

Air Flow Control

77

Page 78: Atdd half day_new_1_up

Embedded Contexts

Sub$ System Two

Input Output

System One

Internal I/O

78

Page 79: Atdd half day_new_1_up

Car Context

Drive&sha*&&

Acceleration De-acceleration Movement

Trans-mission&

Engine&& Wheels&

&

What to test?RPMs?Miles per hour

79

Page 80: Atdd half day_new_1_up

Software Context

Core or API

Developer Acceptance

Test

Customer Acceptance

Test

Middle-tier

GUI

What to test?Elements in an array?Behavior of the system

80

Page 81: Atdd half day_new_1_up

What To Test

BehaviorActions

Changesvia the API

via the same mechanism your GUI doesNot elements in a data structure

Not fields in the database

81

Page 82: Atdd half day_new_1_up

Use Cases and Tests

82

Page 83: Atdd half day_new_1_up

Use Case Template

Name—Identifier to easily reference it by Description—Brief note Actor—Who initiates the use casePre-conditions—What must be true before the use case is initiated Post-conditions—What’s true if the use case successfully executesMain course—Steps that show the sequence of interactions

83

Page 84: Atdd half day_new_1_up

Example: Part One

Name—Check Out CD.Description—Check out a CD for a customer.Actor—Clerk. Pre-conditions—The customer has an identification. The CD

has an identity. Post-conditions—The CD is recorded as rented. The rental

contract is printed.Main Course:

1. The clerk enters the customer identification and CD identifier into the system.

2. The system records the information.3. The system prints a contract that the customer signs.

84

Page 85: Atdd half day_new_1_up

Example: Part Two

Exceptions:1a. Customer identification is not recognized.

Clerk repeats step 1. 1b. The customer violates the CD Rental Limit business rule.

The clerk notifies the customer of the violation.The use case is abandoned.

Business Rule:CD Rental Limit

A customer can rent only three CDs at any one time. Alternatives

3a. The printer jams.The clerk fills out the contract by hand. The use case exits.

85

Page 86: Atdd half day_new_1_up

Acceptance Testing

The Triad create acceptance tests for stories

Tests from general (expected path) ...

... to specific (exceptions)

86

Page 87: Atdd half day_new_1_up

Examples

Rent a CD (expected path)

Bad Customer ID (Enter it wrong)

CD Rental Limit (already has 3. Try 4.)

Print jam (simulate by removing paper)

87

Page 88: Atdd half day_new_1_up

Test Anatomy

88

Page 89: Atdd half day_new_1_up

Test Flow

Setup

Use

Verify

Setup

Use

Verify

Test Flow

89

Page 90: Atdd half day_new_1_up

Test Flow

Ini$al'System'State'

Test'

Setup'(Given))'

Trigger'(When)'

Assert'(Then)'

Final'System'State'and'Output'

Action or Event

ExpectedSystem'State'and'Output'

90

Page 91: Atdd half day_new_1_up

Given/When/Then

Given = Use case pre-conditions When = Main course (or exceptional course)Then = Use case post-conditions

91

Page 92: Atdd half day_new_1_up

Given/when/Then

Given (Setup)Customer has ID (initial system state)CD has ID (initial system state)CD is not currently rented (initial system state)

When (Trigger)Clerk checks out CD (action)

Then (Verify)CD recorded as rented (final system state)Rental contract printed (output)

92

Page 93: Atdd half day_new_1_up

Given/when/Then

GivenCustomer has IDCD has IDCD is not currently rented

WhenClerk checks out CD

Then (Verify)CD recorded as rentedRental contract printed

93

Page 94: Atdd half day_new_1_up

Context Diagram

94

Page 95: Atdd half day_new_1_up

Internal or External Persistence

Output is response to change address

Change address Send mail

External repository for address

Input for send mail

95

Page 96: Atdd half day_new_1_up

Internal or External Persistence

How to test internal persistence? Through another action Through a “see-through” method APIs should be symmetricalAdd/DeleteModify/View

Change address

Internal persistence of address (state)

Send mail

Addressed mail

96

Page 97: Atdd half day_new_1_up

Exercise

Write questions (tests) for:“copying a file from one directory to another”

Describe in terms of:Given: some stateWhen: copy (file, source_directory,

destination_directory)Then: expected state

Source'Directory'Contents'

Des/na/on'Directory'Contents'

Copy'File''

Des/na/on'Directory'Contents?'

Anything'else?''

X' X' X'

Given When Then (Expected)

97

Page 98: Atdd half day_new_1_up

Scenario

B

A X

Copy%

B X

A X

98

Page 99: Atdd half day_new_1_up

Example

Source'Directory'Contents'

Des/na/on'Directory'Contents'

Copy'File''

Des/na/on'Directory''Contents?'

Source'Directory'Contents?'

Content'Comparison?'

Notes'

X,#Y,#Z# D,E,f# X# D,E,F,X# X,Y,Z# (Des-na-on.X#==#Source.X)#

Standard#copy##

X,#Y,#Z# D,E,F,X# X# D,E,F,X# X,Y,Z# (Des-na-on.X#==#Source.X)#

X#overwri?en#

X,#Y,#Z# D,E,F,X# X# D,E,F,X# X,Y,Z# (Des-na-on.X#==#Des-na-on.X)##

X#not#overwri?en#

What about modification date and other attributes? Make more columns

Given When Then (Expected)

99

Page 100: Atdd half day_new_1_up

Example

Source'Directory'Contents'

Des/na/on'Directory'Contents'

Copy'File''

Des/na/on'Directory''Contents?'

Source'Directory'Contents?'

Content'Comparison?'

Notes'

X,#Y,#Z# D,E,f# X# D,E,F,X# X,Y,Z# (Des-na-on.X#==#Source.X)#

Standard#copy##

X,#Y,#Z# D,E,F,X# X# D,E,F,X# X,Y,Z# (Des-na-on.X#==#Source.X)#

X#overwri?en#

X,#Y,#Z# D,E,F,X# X# D,E,F,X# X,Y,Z# (Des-na-on.X#==#Des-na-on.X)##

X#not#overwri?en#

What about modification date and other attributes? Make more columns

Given When Then (Expected)

100

Page 101: Atdd half day_new_1_up

Example

Source'Directory'Contents'

Des/na/on'Directory'Contents'

Copy'File''

Des/na/on'Directory''Contents?'

Source'Directory'Contents?'

Content'Comparison?'

Notes'

X,#Y,#Z# D,E,f# X# D,E,F,X# X,Y,Z# (Des-na-on.X#==#Source.X)#

Standard#copy##

X,#Y,#Z# D,E,F,X# X# D,E,F,X# X,Y,Z# (Des-na-on.X#==#Source.X)#

X#overwri?en#

X,#Y,#Z# D,E,F,X# X# D,E,F,X# X,Y,Z# (Des-na-on.X#==#Des-na-on.X)##

X#not#overwri?en#

What about modification date and other attributes? Make more columns

Given When Then (Expected)

101

Page 102: Atdd half day_new_1_up

Example

Source'Directory'Contents'

Des/na/on'Directory'Contents'

Copy'File''

Des/na/on'Directory''Contents?'

Source'Directory'Contents?'

Content'Comparison?'

Notes'

X,#Y,#Z# D,E,f# X# D,E,F,X# X,Y,Z# (Des-na-on.X#==#Source.X)#

Standard#copy##

X,#Y,#Z# D,E,F,X# X# D,E,F,X# X,Y,Z# (Des-na-on.X#==#Source.X)#

X#overwri?en#

X,#Y,#Z# D,E,F,X# X# D,E,F,X# X,Y,Z# (Des-na-on.X#==#Des-na-on.X)##

X#not#overwri?en#

What about modification date and other attributes? Make more columns

Given When Then (Expected)

102

Page 103: Atdd half day_new_1_up

Tables

103

Page 104: Atdd half day_new_1_up

Tables

Table-driven requirements can reduce ambiguityTables can be testsDiscovery

Tables bring to light overlooked assumptionsDraws out unstated requirements

104

Page 105: Atdd half day_new_1_up

Table Types

Calculation

Action

Data

105

Page 106: Atdd half day_new_1_up

Calculation Table

106

Page 107: Atdd half day_new_1_up

Calc Table Example

Discount Calculation

Item Total Customer Rating Discount Percentage?

$10.00 Good 0%

Given

When

Then

107

Page 108: Atdd half day_new_1_up

Data

!  Exists&(or&should&exist)&–&for&Given&and&Then&

Title Data

Value Name 1 Value Name 2

Value for 1 Value for 2

Another value for 1 Another value for 2

108

Page 109: Atdd half day_new_1_up

Data Table Example

Customer Data

Name ID

James 007

Maxwell 86

Customer Data Name Begins with="’J"

Name ID

James 007

109

Page 110: Atdd half day_new_1_up

Text Requirements

User can log in

What are the rules?

110

Page 111: Atdd half day_new_1_up

Login Grid

User Name Password Result Notes

111

Page 112: Atdd half day_new_1_up

Action Table

Enter enters data into an entry fieldPress initiates a process, such as a Submit buttonCheck sees if a result is equal to an expected

value

112

Page 113: Atdd half day_new_1_up

Action Table Example

Check Out CD

Enter Customer ID 007

Enter CD ID CD2

Press Rent

Check Rented True

Can be just “When” or a stand-alone Given-When-Then

Given

When Then

113

Page 114: Atdd half day_new_1_up

Copy File ExampleCopy%a%file%(happy%path)%%!  Given&a&source&&!  and&target&directory&&&&&&&

File system Directory Name Directory Contents A X,&Y,&Z&B D,E,F

Copy File

Enter Source Directory A

Enter Target Directory B

Enter File name X

Press Copy

!  When&copy&request&is&made&

&&&&&&

!  Then&file&is&copied&&&&&&&

File system Directory Name Directory Contents A X,&Y,&Z&B D,E,F,X

114

Page 115: Atdd half day_new_1_up

The Action

!  Can$drive$a$GUI$

!  Or$a$method$$CopyFile(Directory source, Directory target, Filename file)

115

Page 116: Atdd half day_new_1_up

Business Rules Test

Usually many

One test per rule

116

Page 117: Atdd half day_new_1_up

Example

Rates&

Type& Days& Cost?&Regular( 2( $2(Golden(Oldie( 3( $1.50(Hot(Stuff( 6( $12(Hot(Stuff( 50(( IGBTYOT((

CD(Rental(Rates(Regular(($2(/(2(days(plus($1(/(day((Golden(Oldie($1(/(2(days(plus($(.50(/(day(Hot(Stuff(($4(/(2(days(plus($2(/(day(

117

Page 118: Atdd half day_new_1_up

UI & Business Rules

Email&Valida)on&(Middle/Tier)&

Value&& Valid?&&[email protected], yes,someone@@somewhere.com, no,

!#$%&*+7/=?^_,{|}[email protected], yes,

Email

Ajax call to middle-tier

Submit,

Middle-tier test

118

Page 119: Atdd half day_new_1_up

Alternatives

Can use "script" in tables or separately

119

Page 120: Atdd half day_new_1_up

System Boundaries

120

Page 121: Atdd half day_new_1_up

External Interfaces

!  Connec&ons(to(external(systems(need(to(have(test(doubles((mocks)(

!  Random(events(may(need(to(be(simulated((!  Test(doubles(give(repeatability(and(speed((

External system, device, service

Random events

Time

121

Page 122: Atdd half day_new_1_up

External Interface Example

CD Rental System

Credit Card Processor

Sam’s Bank

Charge Transfer To

Confirmation or Denial Bank

Statement

122

Page 123: Atdd half day_new_1_up

Example of a Credit Card Test Double

CD Rental System

Credit Card Processor Test Double

Charge

Confirmation or Denial

123

Page 124: Atdd half day_new_1_up

Example of a Email Test Double

CD Rental System

Email Server Test Double

Email

Confirmation or Denial

Test verifies that email sent to proper address with proper contents

124

Page 125: Atdd half day_new_1_up

Complex Business Rule and

Separation

125

Page 126: Atdd half day_new_1_up

Complex Business Rule

Field&One& Field&Two& Field&Three& Field&Four& Result&?&>&20& <&50&or&blank& >=100& Y& Allow&Otherwise&or&blank&

DNC& DNC& DNC& Disallow&

DNC& Otherwise& DNC& DNC& Disallow&DNC& DNC& Otherwise&or&

blank&DNC& Disallow&

DNC& DNC& DNC& N&or&blank& Disallow&

A business rule determines whether a user is allowed to perform a certain operation Fields may contain values or be blank

126

Page 127: Atdd half day_new_1_up

Complex Business Rule

Field&One& Result?&>&20& Allow&Blank& Disallow&Otherwise& Disallow&

Field&Two& Result?&<&50& Allow&Blank& Allow&Otherwise& Disallow&

Field&Three& Result&?&>=100& Allow&Blank& Disallow&Otherwise& Disallow&

Field&Four& Result?&&Y& Allow&N& Disallow&Blank& Disallow&Otherwise& ??&

127

Page 128: Atdd half day_new_1_up

Complex Business Rule

Field&One& Field&Two& Field&Three& Field&Four& Result&?&Allow& Allow& Allow& Allow& Allow&Disallow& DNC& DNC& DNC& Disallow&DNC& Disallow& DNC& DNC& Disallow&DNC& DNC& Disallow& DNC& Disallow&DNC& DNC& DNC& Disallow& Disallow&

128

Page 129: Atdd half day_new_1_up

Google Maps

What can you test w/o a UI?

129

Page 130: Atdd half day_new_1_up

Google Maps

No UI?

Search phrase => List of places

Place => Position

Zoom Level => List of maps

Position => List what's there

130

Page 131: Atdd half day_new_1_up

Test Evaluation

131

Page 132: Atdd half day_new_1_up

WARNING!!

Acceptances tests do NOT replace interactive communication!

They provide focus for the communication

132

Page 133: Atdd half day_new_1_up

Test Evaluation

Remove redundant redundancyBusiness domain terms

Shared between customer unit and developer/tester units

Avoid lots of input and output columnsBreak into smaller tables

133

Page 134: Atdd half day_new_1_up

Guidelines

Develop tests & automation separately First, understand Second, automate (if appropriate)

Automate tests for regression Run in continuous integration

Cover 100% of function (if practical)

134

Page 135: Atdd half day_new_1_up

Separation of Concerns

Separate business rules from how results of business rules are displayed

Separate calculation of a business rule (such as a customer rating) from the use of that business rule (such as to give a discount)

Separate each use case or step in a workflow Separate out validation of an entity from use of entity

135

Page 136: Atdd half day_new_1_up

Separation and Abstraction

One story together:When the build fails, send an email to the

administrator Separate and abstracted:

When the build fails, generate an alert When an alert is generated, notify the

responsible individual When the responsible individual is notified, use

that individual’s notification preference (email) Test the notification itself works (e.g. email

works)

136

Page 137: Atdd half day_new_1_up

What is a Good Test?

Fails reliably (for a known reason)

No false positives

No other test covers the same area

NOTE: Tests at the "top" often forced to assume business rules... aim for 1 failure at each level

137

Page 138: Atdd half day_new_1_up

Use Alternate Tables

Sudoku Puzzle 1 4 7

2 5 8 3 6 9

4 7 1 5 8 2

6 9 3 7 1 4

8 2 5 9 3 6

Sudoku Solution 1 6 5 4 9 8 7 3 2 9 2 4 3 5 7 6 8 1 8 7 3 2 1 6 5 4 9 4 9 8 7 3 2 1 6 5 3 5 7 6 8 1 9 2 4 2 1 6 5 4 9 8 7 3 7 3 2 1 6 5 4 9 8 6 8 1 9 2 4 3 5 7 5 4 9 8 7 3 2 1 6

Create tables in alternative forms, if standard not appropriate

Required(Performance((

Puzzle(Type( Time(to(Solve?( Notes(

Easy% .1%seconds%% See%easy%determina2on%

Impossible% 1%second% No%solu2on%%

138

Page 139: Atdd half day_new_1_up

Other uses for Tests

Estimation Aids

Degree of Doneness

139

Page 140: Atdd half day_new_1_up

Process note

Requirement Testable Requirement

Developable Requirement

At least one example for each test

Not schedulable Preferably all examples for all tests

140

Page 141: Atdd half day_new_1_up

process Note

Code%write%

run%

bind%

Code%write%

run%

bind%

Write previous iteration

Write within iteration

141

Page 142: Atdd half day_new_1_up

SCMDevelopers

Watch

Build

Unit Tests

Deploy to Dev

Integration Tests

First Look

Continuous Testing

On Demand Deploy to QA

Manual Testing

142

Page 143: Atdd half day_new_1_up

Not the End.... The Beginning!

143

Page 144: Atdd half day_new_1_up

Objective Review

Understand ATDD in context of SDLC

Learn how to turn requirements into tests

What is a good acceptance test?

ATDD as a communication vehicle

144

Page 145: Atdd half day_new_1_up

Our OutlineTerms and definitions

Requirements and tests

Software development

ATDD examples

Anatomy of a test

Tables

System boundary145

Page 146: Atdd half day_new_1_up

Recap

Primary goalsDiscover ambiguous requirements and gaps in requirements

early onCreate a record of business/development understandingGive feedback on quality

Secondary goalsUse acceptance tests as an executable regression testMeasure your progress towards "done” completenessMeasure the complexity of requirements.Use the tests as a basis for user documentation

146

Page 147: Atdd half day_new_1_up

Rules

Convert requirements into tests

Write tests before code

Write tests in grids (spreadsheets)

Never write code without tests

Include the Golden Triad

147

Page 148: Atdd half day_new_1_up

Further Reading

GROWS Method http://GrowsMethod.com

BDD Behavior Driven Development (by Dan North)

Cucumber http://cukes.info

Tellurim (hosted Cucumber) http://te52.com

Junit http://jaredrichardson.net/articles/junit-tutorial.html

FitNesse fitnesse.org

148

Page 149: Atdd half day_new_1_up

Exercise

You listed your development issues...

Would ATDD help, hurt, or be neutral

Why?

Write down your answer and pass it up

149

Page 150: Atdd half day_new_1_up

Take Aways

What’s a test?

Who writes them?

When are they written?

What do they verify?

Provide an example

Primary benefit?

Secondary benefits?

150

Page 151: Atdd half day_new_1_up

151

151

Page 152: Atdd half day_new_1_up

152

GrowsMethod.com

AgileArtisans.com

[email protected]@GrowsMethod.com

152