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.
Use Case Model Hotel Enter Reserv ation Record Reserv ation Check In Record Check In Hotel Clerk Record Walk-In Check In Record Check OutLonsdaleSystems.com 10
Use Case Record Check OutMain Scenario1. The hotel staff enter the guest’s room number2. The system displays the guest’s stay details3. The system calculates the room chargeAlternate 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 nightBusiness 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 6pmLonsdaleSystems.com Validation 11
Normal check out Verification «verify» Late check out no Record Check Out prior arrangement «verify» «verify» «verify» Check out same day as check in Normal check in No matching guests «verify» «verify» Test Cases Record Reserv ation Check In «verify» Guest has no current reserv ation Hotel «verify» Guest’s room preference notLonsdaleSystems.com av ailable 13
Today = 17/8/2006 Requirements Verification Record Check OutCheck in Checkout Late Room Charge Commentdate time checkout rate time12/8/2006 11:30 am None $120 $600 Normal check out12/8/2006 5:30 pm None $120 $720 Late check out no prior arrangement17/8/2006 11:30 pm None $120 $120 Check out same day as check in LonsdaleSystems.com 14
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 15
Test Case Design TechniquesLonsdaleSystems.com 16
Test Case Design Techniques Black-box Glass-box• Equivalence partitioning • Statement testing• Boundary value analysis • Branch/decision testing• Syntax testing • Condition testing• Decision table testing • Linear code sequence• State transition testing and jump (LCSAJ) … testing • Basis path testing • Data flow testing …LonsdaleSystems.com 17
Equivalence Partitioning Hotel Check Out Check in datebeginning end of time today - 30 days today of time Chargesmallest 1 night x cheapest 30 nights x most largestnumber 0 room rate expensive room number Late check out time 12 am 12 pm 6 pm 12 am none LonsdaleSystems.com 18
Today = 17/8/2006 Equivalence Partitioning Hotel Check OutTest Partitions Check in Checkout Late Room Charge CommentCase date time checkout rate time 1,4,10,13, Invalid check 1 8/7/2006 11:30 am None 120 4800 18 in date 2,4,10,13, 2 12/8/2006 11:30 am None 120 600 17 3,4,10,13, Invalid check 3 27/8/2006 11:30 am None 120 -1200 15 in date 2,5,10,13, 4 12/8/2006 5:30 pm None 120 720 17 2,5,8,13, 5 12/8/2006 2:30 pm 3:00 pm 120 600 17 2,6,8,13, 6 12/8/2006 4:30 pm 3:00 pm 120 720 17 LonsdaleSystems.com 19
Equivalence Partitioning Hotel Check Out Who “tests the test cases”? Today = 17/8/2006Test Partitions Check in Checkout Late Room Charge CommentCase date time checkout rate time Invalid late 2,4,7,13, 7 12/8/2006 11:30 am 10:00 am 120 600 check out 17 time Invalid late 2,5,9,13, 8 12/8/2006 2:30 pm 8:00 pm 120 720 check out 17 time 2,4,10,11, Invalid room 9 12/8/2006 11:30 am None -120 -600 15 rate 2,4,10,12, Invalid room 10 12/8/2006 11:30 am None 10 50 16 rate 2,4,10,14, Invalid room 11 12/8/2006 11:30 am None 240 1200 18 rate LonsdaleSystems.com 20
• Confirms agreement of test outcomes – Expected Test Oracle – Actual• Human test oracle • Automated test oracle – Stakeholders – Spreadsheets – Users – Automated test frameworks and tools – Business analyst But is this testing But is this testing or validating or validating requirements? requirements? LonsdaleSystems.com 21
Requirements vs. Test Cases Requirement Test Case • Abstract • Concrete • “What should be” • “What should be • Validated by • “What should not be” stakeholders • Validated by test • Validation difficult to oracle automate • Test oracle can be automatedLonsdaleSystems.com 23
Test-Driven Requirements Identify Develop test requirements oracle Develop test cases [discrepancies between expected and actual]LonsdaleSystems.com 24
FIT Automated Test FrameworkLonsdaleSystems.com 25
HTML table checkinDate checkoutTime lateCheckoutTime roomRate charge() 1/07/06 11:30 AM None 85 error 18/07/06 11:30 AM None 250 error 12/08/06 11:30 AM None 85 425 12/08/06 12:30 PM None 85 510 12/08/06 11:45 PM 11:30 AM 85 error 12/08/06 2:15 PM 2:30 PM 85 425 12/08/06 2:15 PM 7:30 PM 85 error 12/08/06 7:30 PM 2:30 PM 85 510 12/08/06 11:30 AM None -85 error 16/08/06 11:30 AM None 10 error 22/08/06 11:30 AM None 85 errorTarget system StayColumnFixture stay + checkinDate: var = ""- checkin_date: var + checkoutTime: var = "" + lateCheckoutTime: var = ""- room_rate: var + + roomRate: var = 0 typeDict: var = array( ... FIT+ check_in(var, var) : var - test_stay: var+ check_out(var, var) : var + charge() : var LonsdaleSystems.com Test fixture 27
start eg.HotelFixturepress check inenter room rate 85enter check in date 12/08/06press okpress check out FITenter check out time 11:30 AMenter late check out time Nonecheck charge 426press ok HotelFixture + checkInDate: var = "" + checkOutTime: var = "" + lateCheckOutTime: var = "" + roomRate: var = 0 stay + typeDict: var = array( ... - test_stay: var- checkin_date: var - press_type: var- room_rate: var + checkIn() : var+ check_in(var, var) : var + roomRate(var) : var+ check_out(var, var) : var + checkInDate(var) : var + ok() : var + checkOut() : var + checkOutTime(var) : var + lateCheckOutTime(var) : var + charge() : varLonsdaleSystems.com 28
start eg.MScalcpress clearenter number 2.99999999999999999999999press addenter number 3.00000000000000000000001press equalscheck result 6press subtractenter number 2press equalscheck result 4press clearenter number 4 FITpress multiplyenter number 2press equals MScalc + number: var = 0 + typeDict: var = array( ... - obj: var + __construct() : var + clear() : var MS Calc Auto IT + number(var) : var + add() : var + subtract() : var + multiply() : var + divide() : var + equals() : var LonsdaleSystems.com + result() : var 29