test driven requirements

31
1 Test Driven Requirements Phil Robinson LonsdaleSystems.com

Upload: phil-robinson

Post on 05-Dec-2014

4.313 views

Category:

Technology


7 download

DESCRIPTION

Test-driven development (TDD) is one of the new breed of "agile" software development techniques. At the core of TDD is the simple philosophy that the test cases for a new feature should be designed before the feature is implemented. Advocates of TDD claim that it results in shorter development times and better quality code. They cite early defect detection and the ease of regression testing as the main drivers for this improvement. As TDD grows in popularity, many practitioners are beginning to realise that the core concepts of TDD can be applied to the other phases of the development life cycle. This session explores how the TDD philosophy can be applied to the requirements analysis phase. The session commences with a brief overview of TDD that is followed by a detailed discussion of the concepts behind test-driven requirements (TDR). The discussion focuses on the abstract nature of software requirements and how this leads to difficulties with validation. It is argued that, in contrast, test cases provide concrete examples of requirements that are by nature self-validating. The session concludes with a demonstration of the FIT acceptance test framework designed to support TDR in much the same way that the xUnit test frameworks support TDD.

TRANSCRIPT

LonsdaleSystems.com 1

Test Driven Requirements

Phil Robinson

LonsdaleSystems.com

LonsdaleSystems.com 2

Software Development Trends

LonsdaleSystems.com 3

The Software Development Life Cycle

OperationDep

loymen

t

Construction

Requirements

Desi

gn

Trends propagate backwards through the development life cycle

LonsdaleSystems.com 4

80’s The Structured Trend

OperationDep

loymen

t

Construction

Requirements

StructuredProgramming

StructuredAnalysis

Desi

gnStructuredDesign

LonsdaleSystems.com 5

90’s The Object-Oriented Trend

OperationDep

loymen

t

Construction

Requirements

OOProgramming

OOAnalysis

Desi

gn OODesign

LonsdaleSystems.com 6

00’s The Test-Driven Trend

OperationDep

loymen

t

Construction

Requirements

Test First

Test-Driven Requirements

Desi

gn Test-DrivenDevelopment

LonsdaleSystems.com 7

Brief Overview of Test-Driven Development

LonsdaleSystems.com 8

Test-Driven Development

Functional Requirement

Non-Functional Requirement

Test Design

Code

Refactor

Test

LonsdaleSystems.com 9

Requirements

LonsdaleSystems.com 10

Use Case ModelHotel

Hotel Clerk

Enter Reserv ation

Record Check In

Record Check Out

Record Reserv ation Check In

Record Walk-In Check In

LonsdaleSystems.com 11

Use CaseRecord Check Out

Main Scenario1. The hotel staff enter the guest’s room number2. The system displays the guest’s stay details3. The system calculates the room charge

Alternate Scenariosa) Late check out and no prior arrangement at step 3

a1. The guest is charged for an extra nightb) Check out the same day as check in at step 3

b1. The guest is charged for one night

Business Rulesnumber of nights = today’s date – check in dateroom charge = number of nights x room rateNormal check out time is 12pmGuests may request a later check out timeLate check outs must be before 6pm

Validation

LonsdaleSystems.com 12

Testing Requirements

LonsdaleSystems.com 13

Test Cases Hotel

Normal check in

No matching guests

Guest has no current reserv ation

Guest’s room preference not

av ailable

Record Check Out

Normal check out

Late check out no prior arrangement

Check out same day as check in

Record Reserv ation Check In

«verify»

«verify»

«verify»

«verify»

«verify»

«verify»

«verify»

«verify»

Verification

LonsdaleSystems.com 14

Check out same day as check in

$120$120None11:30 pm17/8/2006

$720

$600

Charge

Late check out no prior arrangement

Normal check out

Comment

$120None5:30 pm12/8/2006

$120None11:30 am12/8/2006

Room rate

Late checkout time

Checkout time

Check in date

Today = 17/8/2006Requirements Verification

Record Check Out

LonsdaleSystems.com 15

In-Depth Testing

• Maximum length of stay?• Maximum and minimum room rates?• Check out same day as check in

– With late check out no prior arrangement?– Check in after 12am?

LonsdaleSystems.com 16

Test Case Design Techniques

LonsdaleSystems.com 17

Test Case Design Techniques

Black-box• Equivalence partitioning• Boundary value analysis• Syntax testing• Decision table testing• State transition testing

Glass-box• Statement testing• Branch/decision testing• Condition testing• Linear code sequence

and jump (LCSAJ) testing

• Basis path testing • Data flow testing

LonsdaleSystems.com 18

Check in datebeginning

of time today - 30 days todayend

of time

Late check out time12 pm 6 pm12 am 12 am none

Equivalence PartitioningHotel Check Out

Chargesmallestnumber 0

1 night x cheapest room rate

30 nights x most expensive room

largestnumber

LonsdaleSystems.com 19

7201203:00 pm4:30 pm12/8/20062,6,8,13, 176

6001203:00 pm2:30 pm12/8/20062,5,8,13, 175

600120None11:30 am12/8/20062,4,10,13,172

720

-1200

4800

Charge

Invalid check in date

Invalid check in date

Comment

2,5,10,13,17

3,4,10,13,15

1,4,10,13,18

Partitions

120None5:30 pm12/8/20064

120None11:30 am27/8/20063

120None11:30 am8/7/20061

Room rate

Late checkout time

Checkout time

Check in date

Test Case

Today = 17/8/2006Equivalence Partitioning

Hotel Check Out

LonsdaleSystems.com 20

Invalid late check out time

60012010:00 am11:30 am12/8/20062,4,7,13, 177

Invalid late check out time

7201208:00 pm2:30 pm12/8/20062,5,9,13, 178

Invalid room rate-600-120None11:30 am12/8/20062,4,10,11,

159

1200

50

Charge

Invalid room rate

Invalid room rate

Comment

2,4,10,14,18

2,4,10,12,16

Partitions

240None11:30 am12/8/200611

10None11:30 am12/8/200610

Room rate

Late checkout time

Checkout time

Check in date

Test Case

Today = 17/8/2006

Equivalence PartitioningHotel Check Out Who “tests the

test cases”?

LonsdaleSystems.com 21

Test Oracle• Confirms agreement of

test outcomes– Expected– Actual

• Human test oracle– Stakeholders– Users– Business analyst

• Automated test oracle– Spreadsheets– Automated test frameworks and tools

But is this testing or validating requirements?

But is this testing or validating requirements?

LonsdaleSystems.com 22

Test-Driven Requirements

LonsdaleSystems.com 23

Requirements vs. Test Cases

Requirement• Abstract• “What should be”• Validated by

stakeholders• Validation difficult to

automate

Test Case• Concrete• “What should be• “What should not be”• Validated by test

oracle• Test oracle can be

automated

LonsdaleSystems.com 24

Test-Driven Requirements

Identifyrequirements

Develop test cases

Develop test oracle

[discrepancies between expected and actual]

LonsdaleSystems.com 25

FIT Automated Test Framework

LonsdaleSystems.com 26

Framework For Integrated Tests

(FIT)

• fit.c2.com/• fitnesse.org/

LonsdaleSystems.com 27

checkinDate checkoutTime lateCheckoutTime roomRate charge()1/07/06 11:30 AM None 85 error

18/07/06 11:30 AM None 250 error12/08/06 11:30 AM None 85 42512/08/06 12:30 PM None 85 51012/08/06 11:45 PM 11:30 AM 85 error12/08/06 2:15 PM 2:30 PM 85 42512/08/06 2:15 PM 7:30 PM 85 error12/08/06 7:30 PM 2:30 PM 85 51012/08/06 11:30 AM None -85 error16/08/06 11:30 AM None 10 error22/08/06 11:30 AM None 85 error

stay

- checkin_date: var- room_rate: var

+ check_in(var, var) : var+ check_out(var, var) : var

StayColumnFixture

+ checkinDate: var = ""+ checkoutTime: var = ""+ lateCheckoutTime: var = ""+ roomRate: var = 0+ typeDict: var = array( ...- test_stay: var

+ charge() : var

FIT

HTML table

Test fixture

Target system

LonsdaleSystems.com 28

HotelFixture

+ checkInDate: var = ""+ checkOutTime: var = ""+ lateCheckOutTime: var = ""+ roomRate: var = 0+ typeDict: var = array( ...- test_stay: var- press_type: var

+ checkIn() : var+ roomRate(var) : var+ checkInDate(var) : var+ ok() : var+ checkOut() : var+ checkOutTime(var) : var+ lateCheckOutTime(var) : var+ charge() : var

stay

- checkin_date: var- room_rate: var

+ check_in(var, var) : var+ check_out(var, var) : var

start eg.HotelFixturepress check inenter room rate 85enter check in date 12/08/06press okpress check outenter check out time 11:30 AMenter late check out time Nonecheck charge 426press ok

FIT

LonsdaleSystems.com 29

start eg.MScalcpress clearenter number 2.99999999999999999999999press addenter number 3.00000000000000000000001press equalscheck result 6press subtractenter number 2press equalscheck result 4press clearenter number 4press multiplyenter number 2press equals

MScalc

+ number: var = 0+ typeDict: var = array( ...- obj: var

+ __construct() : var+ clear() : var+ number(var) : var+ add() : var+ subtract() : var+ multiply() : var+ divide() : var+ equals() : var+ result() : var

MS Calc

FIT

Auto IT

LonsdaleSystems.com 30

FIT Demo…

LonsdaleSystems.com 31

Questions?

Phil Robinson

LonsdaleSystems.com