acceptance test driven development at starwest 2014

150
ATDD Acceptance Test Driven Development Jared Richardson Agile Artisans

Upload: jaredrrichardson

Post on 11-Jun-2015

393 views

Category:

Software


1 download

DESCRIPTION

This is my half day Acceptance Test Driven Development course as given in Anaheim at StarWest 2014 (October). It's based on Ken Pugh's 1/2 day tutorial.

TRANSCRIPT

Page 1: Acceptance Test Driven Development at StarWest 2014

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

Page 2: Acceptance Test Driven Development at StarWest 2014

Who are you?

Page 3: Acceptance Test Driven Development at StarWest 2014

Jared Richardson

Author Ship It! and Career 2.0

Screencast editor PragProg.com

2nd public signatory of the Agile Manifesto

Started AgileRTP in 2007!

Agile coach

AgileArtisans.com

Page 4: Acceptance Test Driven Development at StarWest 2014

Who are you?

Page 5: Acceptance Test Driven Development at StarWest 2014

What would you say you do here?

Roles?

Responsibilities?

Why are you here?

What are your tests for this session?

Page 6: Acceptance Test Driven Development at StarWest 2014

Objectives

Understand ATDD in context of SDLC

Learn how to turn requirements into tests

What is a good acceptance test?

ATDD as a communication vehicle

Page 7: Acceptance Test Driven Development at StarWest 2014

Outline

Terms and definitions

Requirements and tests

Software development

ATDD examples

Anatomy of a test

Tables

System boundary

Page 8: Acceptance Test Driven Development at StarWest 2014

Breaks

Halfway (90 minutes)

Page 9: Acceptance Test Driven Development at StarWest 2014

One Rule

There are exceptions to every statement

Except this one

Page 10: Acceptance Test Driven Development at StarWest 2014

What is an Acceptance test?

External view of the system

Examines visible effects

Inputs

Outputs

State changes

External interfaces

Page 11: Acceptance Test Driven Development at StarWest 2014

Definitions

Acceptance criteria -> General idea

Acceptance test -> specific. Pass/fail.

Implementation independent

Triad -> Customer, developer, tester

Page 12: Acceptance Test Driven Development at StarWest 2014

Fast Car

Who wants one?

Criteria

Closed course. Measure acceleration.

Test

Accelerate 0 to 60 in X seconds

Page 13: Acceptance Test Driven Development at StarWest 2014

Fast Car

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 200 miles. Cost of 7 billion.

Page 14: Acceptance Test Driven Development at StarWest 2014

Why?Rework down from 60% to 20%

Workflows work 1st time

Little room miscommunication

Saves time

Getting business rules RIGHT

Game changing

Tighter cross functional team integration

Crisp visible story completion criteria

Automation yields reduced testing time

Page 15: Acceptance Test Driven Development at StarWest 2014

Requirements and Tests

Page 16: Acceptance Test Driven Development at StarWest 2014

Requirement

Needed by a user to solve a problem

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

Page 17: Acceptance Test Driven Development at StarWest 2014

Requirements Include

Functions (what software does)

Constraints (limits)

Page 18: Acceptance Test Driven Development at StarWest 2014

Requirements Should not

Include

Implementation details

Specific manifestation

Page 19: Acceptance Test Driven Development at StarWest 2014

A Brownie Spec

Ingredient        Parts  by  weight

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

Page 20: Acceptance Test Driven Development at StarWest 2014

Brownie Spec

a.  Whip  eggs  in  large  bowl  on  high  speed  un3l  light  and  fluffy.  b.  Combine  sugars,  cocoa,  salt,  and  leavening;  add  to  beaten  eggs,  and  whip  on  high  speed  un3l  thick.  c.  Add  shortening  slowly  while  mixing  on  low  speed.  d.  Scrape  bowl  and  whip  on  high  speed  un3l  thick.  e.  Mix  flour,  nuts,  and  flavors  together  and  fold  into  baDer;  mix  un3l  uniform.  f.  Pour  baDer  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  un3l  done  (30  to  45  minutes).  

Page 21: Acceptance Test Driven Development at StarWest 2014

Requirements and tests

Inter-related

Can't have one w/o the other

Failing test...

... is a requirement

Passing test...

... valid system spec

Page 22: Acceptance Test Driven Development at StarWest 2014

ATDD as a Prism

Requirements

Tests

ATDD

Page 23: Acceptance Test Driven Development at StarWest 2014

Software Development

Page 24: Acceptance Test Driven Development at StarWest 2014

Exercise What Issues?

Current software dev process

Write down your own

Groups of 3 to 8

Pass to front

Page 25: Acceptance Test Driven Development at StarWest 2014

Developers Testers

Customers

The Team

Page 26: Acceptance Test Driven Development at StarWest 2014

Customer Unit

Product owner

Business analysts

Users

QA

Page 27: Acceptance Test Driven Development at StarWest 2014

Developer/Tester Unit

Programmers

Testers

QA

Page 28: Acceptance Test Driven Development at StarWest 2014

Developers Testers

Customers

The Triad

Page 29: Acceptance Test Driven Development at StarWest 2014

Traditional Value Stream

Elicit&Requirements&

Analyze&Requirements& Design&&

Code& Test&

Why go back?

Deploy&

Page 30: Acceptance Test Driven Development at StarWest 2014

Mistakes?

Misunderstandings

Missed requirements

Mis other

Page 31: Acceptance Test Driven Development at StarWest 2014

Mistakes

Feedback corrects misunderstandings

Quick feedback better than slow feedback

Page 32: Acceptance Test Driven Development at StarWest 2014

Desired Actual

Slow Feedback

Actual

Fast Feedback

Page 33: Acceptance Test Driven Development at StarWest 2014

Agile Value Stream

Elicit&Requirements&

Analyze&Requirements&With&Tests&

Design&&

Code&With&Tests& Deploy&

Page 34: Acceptance Test Driven Development at StarWest 2014

Move Testing Forward

Page 35: Acceptance Test Driven Development at StarWest 2014

Two Types of Testing

To find defects

To prevent defects

Page 36: Acceptance Test Driven Development at StarWest 2014

Finding Defects

Waste

Identifying mistakes

flickr.com/photos/mag3737/444557606

Page 37: Acceptance Test Driven Development at StarWest 2014

preventing Defects

Saves development time

Saves QA time

Saves money

Page 38: Acceptance Test Driven Development at StarWest 2014

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%

Page 39: Acceptance Test Driven Development at StarWest 2014

Two Ways

Code%write% run%bind%

Code%write%

run%

bind%

Page 40: Acceptance Test Driven Development at StarWest 2014

Test First

Write the test first

Write the code after

One molds the other

First in wins

Page 41: Acceptance Test Driven Development at StarWest 2014

Testing Strategies

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

Page 42: Acceptance Test Driven Development at StarWest 2014

Testing Focus

Page 43: Acceptance Test Driven Development at StarWest 2014

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?

Page 44: Acceptance Test Driven Development at StarWest 2014

Acceptance Testing

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

Core*Business*Logic**

UI*

Persistence*

Acceptance Tests

Page 45: Acceptance Test Driven Development at StarWest 2014

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

Page 46: Acceptance Test Driven Development at StarWest 2014

Acceptance Test Examples

Page 47: Acceptance Test Driven Development at StarWest 2014

Temperature

Input in Celsius

Output in Fahrenheit

What tests?

Page 48: Acceptance Test Driven Development at StarWest 2014

Temperature

Page 49: Acceptance Test Driven Development at StarWest 2014

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

Page 50: Acceptance Test Driven Development at StarWest 2014

Is This A Good Spec?

Page 51: Acceptance Test Driven Development at StarWest 2014

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%

Page 52: Acceptance Test Driven Development at StarWest 2014

Rule Table => Test

Page 53: Acceptance Test Driven Development at StarWest 2014

Another Business Rule

Email coupon codes

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

Discount an item or the order?

Page 54: Acceptance Test Driven Development at StarWest 2014

Implementation

Testing script

Program interface

Xunit framework

ATDD framework

Page 55: Acceptance Test Driven Development at StarWest 2014

Testing Script

Tools for testers

(Usually) GUI based

Page 56: Acceptance Test Driven Development at StarWest 2014

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

Page 57: Acceptance Test Driven Development at StarWest 2014

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%

Page 58: Acceptance Test Driven Development at StarWest 2014

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));

} }

Page 59: Acceptance Test Driven Development at StarWest 2014

Fit Test

Page 60: Acceptance Test Driven Development at StarWest 2014

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

Page 61: Acceptance Test Driven Development at StarWest 2014

Context

Page 62: Acceptance Test Driven Development at StarWest 2014

Context Diagram

Process'

User

Reports

Commands Views

Page 63: Acceptance Test Driven Development at StarWest 2014

Another Context Diagram

Process'

User

Another System Shared Database

Commands

Views

Requests

Responses

Stores

Retrievals

Page 64: Acceptance Test Driven Development at StarWest 2014

Engine Controller

Engine&Controller&

Engine Rotation Speed

Gasoline Flow Control

Spark Timing

Acceleration / De-acceleration

Air Flow Control

Page 65: Acceptance Test Driven Development at StarWest 2014

Embedded Contexts

Sub$ System Two

Input Output

System One

Internal I/O

Page 66: Acceptance Test Driven Development at StarWest 2014

Car Context

Drive&sha*&&

Acceleration De-acceleration Movement

Trans-mission&

Engine&& Wheels&

&

Page 67: Acceptance Test Driven Development at StarWest 2014

Software Context

Core or API

Developer Acceptance

Test

Customer Acceptance

Test

Middle-tier

GUI

Page 68: Acceptance Test Driven Development at StarWest 2014

Use Cases and Tests

Page 69: Acceptance Test Driven Development at StarWest 2014

Use Case Template

Name—Iden3fier  to  easily  reference  it  by    DescripGon—Brief  note    Actor—Who  ini3ates  the  use  case  Pre-­‐condiGons—What  must  be  true  before  the  use  case  is  ini3ated    Post-­‐condiGons—What  is  true  if  the  use  case  successfully  executes  Main  course—Steps  that  show  the  sequence  of  interac3ons

Page 70: Acceptance Test Driven Development at StarWest 2014

Example: Part One

Name—Check  Out    CD.  DescripGon—Check  out  a  CD  for  a  customer.  Actor—Clerk.    Pre-­‐condiGons—The  customer  has  an  iden3fica3on.  The  CD  has  an  iden3ty.    

Post-­‐condiGons—The  CD  is  recorded  as  rented.  The  rental  contract  is  printed.  

Main  Course:    1.  The  clerk  enters  the  customer  iden3fica3on  and  CD  iden3fier  into  the  system.  

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

Page 71: Acceptance Test Driven Development at StarWest 2014

Example: Part Two

Alterna3ves:    flow  that  allows  the  use  case  to  be  successful  even  if  some  condi3on  occurs  

Excep3ons:  condi3ons  can  occur  that  may  not  allow  it  to  reach  its  post-­‐condi3ons.  

Business  Rules:  rules  that  must  be  followed  regardless  of  technology    

Note:  Alterna3ves  and  Excep3ons  could  become  separate  story(ies)  if  requires  significant  effort  

Excep3ons  and  Alterna3ves  numbered  with  reference  to  Main  Course  steps

Page 72: Acceptance Test Driven Development at StarWest 2014

Example: Part ThreeExcepGons:  1a.   Customer  iden3fica3on  is  not  recognized.  Clerk  repeats  step  1.    

1b.  The  customer  violates  the  CD  Rental  Limit  business  rule.     The  clerk  no3fies  the  customer  of  the  viola3on.     The  use  case  is  abandoned.    

Business  Rule:  CD  Rental  Limit       A  customer  can  rent  only  three  CDs  at  any  one  3me.    

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

Page 73: Acceptance Test Driven Development at StarWest 2014

Acceptance Testing

The Triad create acceptance tests for stories

Tests from general (expected path) ...

... to specific (exceptions)

Page 74: Acceptance Test Driven Development at StarWest 2014

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)

Page 75: Acceptance Test Driven Development at StarWest 2014

Test Anatomy

Page 76: Acceptance Test Driven Development at StarWest 2014

Test Flow

Setup

Use

Verify

Page 77: Acceptance Test Driven Development at StarWest 2014

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'

Page 78: Acceptance Test Driven Development at StarWest 2014

Given/When/Then

Given  =  Use  case  pre-­‐condi3ons    When  =  Main  course  (or  excep3onal  course)  Then  =  Use  case  post-­‐condi3ons  

Page 79: Acceptance Test Driven Development at StarWest 2014

Given/when/Then

Given  (Setup)     Customer  has  ID  (ini3al  system  state)     CD  has  ID  (ini3al  system  state)     CD  is  not  currently  rented  (ini3al  system  state)  When  (Trigger)     Clerk  checks  out  CD  (ac3on)    Then    (Verify)     CD  recorded  as  rented  (final  system  state)     Rental  contract  printed  (output)  

Page 80: Acceptance Test Driven Development at StarWest 2014

Context Diagram

Page 81: Acceptance Test Driven Development at StarWest 2014

Internal or External Persistence

Output is response to change address

Change address Send mail

External repository for address

Input for send mail

Page 82: Acceptance Test Driven Development at StarWest 2014

Internal or External Persistence

How  to  test  internal  persistence?    Through  another  ac3on    Through  a  “see-­‐through”  method      

Change address

Internal persistence of address (state)

Send mail

Addressed mail

Page 83: Acceptance Test Driven Development at StarWest 2014

ExerciseWrite  ques3ons  (tests)  for:     “copying  a  file  from  one  directory  to  another”  Describe  in  terms  of:  Given:  some  state  When:  copy  (file,  source_directory,  des3na3on_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)

Page 84: Acceptance Test Driven Development at StarWest 2014

Scenario

B

A X

Copy%

B X

A X

Page 85: Acceptance Test Driven Development at StarWest 2014

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)

Page 86: Acceptance Test Driven Development at StarWest 2014

Tables

Page 87: Acceptance Test Driven Development at StarWest 2014

Tables

Table-­‐driven  requirements  can  reduce  ambiguity  over  free  text  

Tables  can  be  the  tests  Discovery    Filling  out  tables  may  bring  to  light  suppressed  premises    Unstated  requirements  or  assump7ons  

Page 88: Acceptance Test Driven Development at StarWest 2014

Table Types

Calculation

Action

Data

Page 89: Acceptance Test Driven Development at StarWest 2014

Calculation Table

Page 90: Acceptance Test Driven Development at StarWest 2014

Calc Table Example

Discount Calculation

Item Total Customer Rating Discount Percentage?

$10.00 Good 0%

Given

When

Then

Page 91: Acceptance Test Driven Development at StarWest 2014

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

Page 92: Acceptance Test Driven Development at StarWest 2014

Data Table Example

Customer Data

Name ID

James 007

Maxwell 86

Customer Data Name Begins with="’J"

Name ID

James 007

Page 93: Acceptance Test Driven Development at StarWest 2014

Action Table

Enter  enters  data  into  an  entry  field  Press  ini3ates  a  process,  such  as  a  Submit  buDon  Check  sees  if  a  result  is  equal  to  an  expected  value

Page 94: Acceptance Test Driven Development at StarWest 2014

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

Page 95: Acceptance Test Driven Development at StarWest 2014

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

Page 96: Acceptance Test Driven Development at StarWest 2014

The Action

!  Can$drive$a$GUI$

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

Page 97: Acceptance Test Driven Development at StarWest 2014

Copy File ExampleNon$existent*file***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 Q

Press Copy Error_file_does_not_exist

!  When&copy&request&is&made&for&a&non;existent&file&,&an&error&is&generated&&&&&

!  Anything&else?&&&&&

Page 98: Acceptance Test Driven Development at StarWest 2014

Given/When/Then revsited

Given  (Setup)     Customer  has  ID  (ini3al  system  state)     CD  has  ID  (ini3al  system  state)     CD  is  not  currently  rented  (ini3al  system  state)  When  (Trigger)     Clerk  checks  out  CD  (ac3on)    Then    (Verify)     CD  recorded  as  rented  (final  system  state)     Rental  contract  printed  (output)  

Page 99: Acceptance Test Driven Development at StarWest 2014

Check Out A CD!  Given&Customer&has&ID&&&&&&&and&CD&has&ID&&&&&&&and&CD&is&not&currently&rented&&

Customer Data

Name ID

James 007

CD Data

ID Title Rented

CD2 Beatles Greatest Hits No

Page 100: Acceptance Test Driven Development at StarWest 2014

CHECKING OUT CONTINUED

! When%a%clerk%checks%out%a%CD:%

Check Out CD

Enter Customer ID 007

Enter CD ID CD2

Press Rent

Page 101: Acceptance Test Driven Development at StarWest 2014

CONTINUED FURTHER...

!  Then%the%CD%is%recorded%as%rented%and%a%rental%contract%is%printed:%%

CD Data

ID Title Rented Customer ID

CD2 Beatles Greatest Hits Yes 007

Rental Contract

Customer ID Customer Name CD ID CD Title

007 James CD2 Beatles Greatest Hits

Page 102: Acceptance Test Driven Development at StarWest 2014

THE ACTION

!  Can$drive$a$GUI$

!  Or$a$method$$Rent(CustomerID aCustomer, CDID aCD);

Page 103: Acceptance Test Driven Development at StarWest 2014

ASSUMPTIONS

Assume...- No other data changes- Can select customers (or CDs) from a list

Could have tests for these assumptions...

Page 104: Acceptance Test Driven Development at StarWest 2014

Test ExampleCheck&that&no&other&elements&changed&on&check1out&

!  Given&Customers&and&CDs&&&&&&&& Customer Data

Name ID James 007 Maxwell 86

CD Data

ID Title Rented Customer ID

CD2 Beatles Greatest Hits No

CD3 Lucy&Michelle&Hits No

CD4 Janet&Jackson&Hits Yes 86

Page 105: Acceptance Test Driven Development at StarWest 2014

Test Example 1Check&that&no&other&elements&changed&on&check1out&

!  Given&Customers&and&CDs&&&&&&&& Customer Data

Name ID James 007 Maxwell 86

CD Data

ID Title Rented Customer ID

CD2 Beatles Greatest Hits No

CD3 Lucy&Michelle&Hits No

CD4 Janet&Jackson&Hits Yes 86

Page 106: Acceptance Test Driven Development at StarWest 2014

Test Example 2

! When%a%clerk%checks%out%a%CD:%

Check Out CD

Enter Customer ID 007

Enter CD ID CD2

Press Rent

Page 107: Acceptance Test Driven Development at StarWest 2014

Test Example 3

!  Then%only%the%rented%CD%is%affected%%Customer Data Name ID James 007 Maxwell 86

CD Data

ID Title Rented Customer ID

CD2 Beatles Greatest Hits Yes 007

CD3 Lucy%Michelle%Hits No

CD4 Janet%Jackson%Hits Yes 86

Page 108: Acceptance Test Driven Development at StarWest 2014

Selection ExampleCheck&that&a&customer&can&be&selected&&

!  Given&Customers&&&&&&&

Customer Data Name ID James 007 Maxwell 86

Check Out CD

Enter Customer ID 86

Press Select

!  When&a&Customer&is&selected&&

&&&&&&

!  Then&the&correct&customer&is&selected&&&&&&&

Selected Customer Name ID Maxwell 86

Page 109: Acceptance Test Driven Development at StarWest 2014

Business Rules Test

Usually many

One test per rule

Page 110: Acceptance Test Driven Development at StarWest 2014

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(

Page 111: Acceptance Test Driven Development at StarWest 2014

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

Page 112: Acceptance Test Driven Development at StarWest 2014

Alternatives

Can use "script" in tables or separately

Page 113: Acceptance Test Driven Development at StarWest 2014

Copy A File (Happy Path)

Given directory A with files X, Y, & Z

And directory B with files D, E, F

When file X is copied from A to B

Then directory A has files X, Y, & Z

and directory B has files D, E, F, & X

Page 114: Acceptance Test Driven Development at StarWest 2014

CD Rental (happy Path)

Given customer James with ID 007

And CD ID CD2 w/title "Beatle's Greatest Hits" is not rented

When customer 007 rents CD2

And a rental contract is printed with: name James, customer ID 007, CD ID CD2, and CD title "Beatle's Greatest Hits"

Page 115: Acceptance Test Driven Development at StarWest 2014

Business Rule Script Test

Rates&

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

When(a(CD(of(type(Regular(is(rented(for(2(days(Then(the(cost(is($2(When(a(CD(of(type(Golden(Oldie(is(rented(for(3(days((Then(the(cost(is($1.50((When(a(CD(of(type(Hot(Stuff(is(rented(for(6(days(Then(the(cost(is($12((

Page 116: Acceptance Test Driven Development at StarWest 2014

System Boundaries

Page 117: Acceptance Test Driven Development at StarWest 2014

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

Page 118: Acceptance Test Driven Development at StarWest 2014

External Interface Example

CD Rental System

Credit Card Processor

Sam’s Bank

Charge Transfer To

Confirmation or Denial Bank

Statement

Page 119: Acceptance Test Driven Development at StarWest 2014

Example of a Credit Card Test Double

CD Rental System

Credit Card Processor Test Double

Charge

Confirmation or Denial

Page 120: Acceptance Test Driven Development at StarWest 2014

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

Page 121: Acceptance Test Driven Development at StarWest 2014

Complex Business Rule and

Separation

Page 122: Acceptance Test Driven Development at StarWest 2014

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

Page 123: Acceptance Test Driven Development at StarWest 2014

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& ??&

Page 124: Acceptance Test Driven Development at StarWest 2014

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&

Page 125: Acceptance Test Driven Development at StarWest 2014

Business Rule & UI

Two  business  rule  results  Allow  Disallow  

Alternate  UI  manifesta3ons  of  the  business  rule  Disable  the  buDon  if  disallowed  Hide  the  buDon  if  disallowed.  Display  dialog  box  if  disallowed  and  they  push  the  buDon    

To  cut  down  tes3ng,  expose  business  rule  test    5  +  2  tests,  rather  than  5  *  2  tests  

Page 126: Acceptance Test Driven Development at StarWest 2014

Separate UI from Business Rule

Business'Rule'Display'Requirement''

Business'Rule'Result' UI'Display?' Notes''

Disallow' Disable'Bu9on'

Allow' Enable'Bu9on'' Take'to'some'entry'screen'

End@to@end'Business'Rule'Test'

Sample'user'ID' Business'Rule'Result' UI'Display?'

10345' Allow' Enable'Bu9on'

5555' Disallow'' Disable'Bu9on'

Third'column'will'change'if'Business'Rule'Display'Requirement'changes''

Page 127: Acceptance Test Driven Development at StarWest 2014

Separate the Model from the View

Rental Contract

Customer ID Customer Name CD ID CD Title Rental Due

007 James CD2 Beatles Greatest Hits 1/23/2011

Rental Contract Template The customer named <Customer Name> with the ID <Customer ID>, hereafter referred to as the Renter, has rented the CD identified by <CD ID> with the title "<CD Title>," hereafter referred to as the Rented CD, from Sam's Lawn Mower Repair and CD Rental Store, hereafter referred to as the Rentee. The Renter promises to return the Rented CD to the Rentee by <Rental Due>. If said Renter exceeds .. blah…blah…blah

Rental Contract Printout The customer named James with the ID 007, hereafter referred to as the Renter, has rented the CD identified by CD2 with the title "Beatle's Greatest Hits," hereafter referred to as the Rented CD, from Sam's Lawn Mower Repair and CD Rental Store, hereafter referred to as the Rentee. The Renter promises to return the Rented CD to the Rentee by 1/23/2011. If said Renter exceeds .. blah…blah…blah

Page 128: Acceptance Test Driven Development at StarWest 2014

Separate the Event from the Response

Logon%Sequence%%

Username% Password% Result?% Notes%

Sam$ 123$ Bad_password$ 1st$bad$

George$ 1123$ No_user$ 2nd$bad$

Sam$ 1234$ Bad_password$ 3rd$bad$

Same$$ 12345$ Security_viola?on$ 4th$bad$

Logon%Ac9ons%%

Result% Ac9on%

Bad_password$ Display$“password$bad”$

No_user$$ Display$“no$user”$

Security_viola?on$ Send$enforcement$team$

Page 129: Acceptance Test Driven Development at StarWest 2014

Google Maps

What can you test w/o a UI?

Page 130: Acceptance Test Driven Development at StarWest 2014

Google Maps

No UI?

Search phrase => List of places

Place => Position

Zoom Level => List of maps

Position => List what's there

Page 131: Acceptance Test Driven Development at StarWest 2014

Test Evaluation

Page 132: Acceptance Test Driven Development at StarWest 2014

WARNING!!

Acceptances tests do NOT replace interactive communication!

They provide focus for the communication

Page 133: Acceptance Test Driven Development at StarWest 2014

Test Evaluation

Remove  redundant  redundancy  Business  domain  terms    Shared  between  customer  unit  and  developer/tester  units  

Avoid  lots  of  input  and  output  columns  Break  into  smaller  tables  (example  follows)

Page 134: Acceptance Test Driven Development at StarWest 2014

Big Table to Smaller OneBig$Data$Test$

F1$ F2$ F3$ F4$ …$ Valid?$$ Reason$

1$ 2$ 3$ 6$ Y$

1$ 3$ 3$ 6$ N$ F2$+$F3$>$5$

1$ 3$ 1$ 6$ N$ F2$+$F3$<$5$$

…$Lots$more$$for$other$rules$

Big$Data$Test$for$F2EF3$$

F2$ F3$ Valid?$$ Reason$

2$ 3$ Y$

3$ 3$ N$ F2$+$F3$>$5$

3$ 1$ N$ F2$+$F3$<$5$$

If can apply default values to F1, F4 etc., then could be:

Page 135: Acceptance Test Driven Development at StarWest 2014

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)

Page 136: Acceptance Test Driven Development at StarWest 2014

Separation of Concerns

Separate  business  rules  from  how  results  of  business  rules  are  displayed      

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

Separate  each  use  case  or  step  in  a  workflow    Separate  out  valida3on  of  an  en3ty  from  use  of  en3ty  

Page 137: Acceptance Test Driven Development at StarWest 2014

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,  no3fy  the  responsible  individual    

When  the  responsible  individual  is  no3fied,  use  that  individual’s  no3fica3on  preference  (email)    

Test  the  no3fica3on  itself    works  (e.g.  email  works)

Page 138: Acceptance Test Driven Development at StarWest 2014

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

Page 139: Acceptance Test Driven Development at StarWest 2014

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%%

Page 140: Acceptance Test Driven Development at StarWest 2014

Story Tests Not Enough

Disk%Monitor%

Report'Error'If'Disk'Does'Not'Respond'Within'1'Second

Power%Saver%%

Spin'Down'Disk'If'Not'Accessed'In'Past'Minute

Page 141: Acceptance Test Driven Development at StarWest 2014

Other uses for Tests

Estimation Aids

Degree of Doneness

Page 142: Acceptance Test Driven Development at StarWest 2014

Process note

Requirement Testable Requirement

Developable Requirement

At least one example for each test

Not schedulable Preferably all examples for all tests

Page 143: Acceptance Test Driven Development at StarWest 2014

process Note

Code%write%

run%

bind%

Code%write%

run%

bind%

Write previous iteration

Write within iteration

Page 144: Acceptance Test Driven Development at StarWest 2014

Not the End.... The Beginning!

Page 145: Acceptance Test Driven Development at StarWest 2014

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

Page 146: Acceptance Test Driven Development at StarWest 2014

Our OutlineTerms and definitions

Requirements and tests

Software development

ATDD examples

Anatomy of a test

Tables

System boundary

Page 147: Acceptance Test Driven Development at StarWest 2014

Recap

Primary  goals  Discover  ambiguous  requirements  and  gaps  in  requirements  early  on.  

Create  a  record  of  business/development  understanding.  Give  feedback  on  quality  .  

Secondary  goals  Use  acceptance  tests  as  an  executable  regression  test.  Measure    your  progress  towards  "done”  completeness.  Measure  the  complexity  of  requirements.  Use  the  tests  as  a  basis  for  user  documenta3on.

Page 148: Acceptance Test Driven Development at StarWest 2014

Exercise

You listed your development issues...

Would ATDD help, hurt, or be neutral

Why?

Write down your answer and pass it up

Page 149: Acceptance Test Driven Development at StarWest 2014

Agility Responding to Change

You're my customers

You provided your requirements

Now play the user/tester

Were your requirements met?

What else needs to be done?

Page 150: Acceptance Test Driven Development at StarWest 2014