You are on page 1of 29

IBM Software Group Rational software ®

IBM Software Group

Traceability From Use Cases To Test Cases

Peter Zielczynski, Ph.D.


The “A” Consulting Team
PZielczynski@tact.com

RM14

Rational User Conference 2003 Group


IBM Software Rational software

Agenda
f Overview of the requirements types
f Traceability between requirements
f Actors and Use Cases
f How to create Test Cases from Use Cases
f Mapping to RUP
f Conclusions

1
Rational User Conference 2003 Group
IBM Software Rational software

What is a requirement?
f A requirement is defined as "a condition or capability to
which a system must conform"
ƒ A capability needed by a customer or user to solve a problem or
achieve an objective
ƒ A capability that must be met or possessed by a system to satisfy a
contract, standard, specification, regulation or other formally
imposed document
ƒ A restriction imposed by a stakeholder

Rational User Conference 2003 Group


IBM Software Rational software

Requirements pyramid

Needs

Features

Use Cases Supp

Scenarios

Test Cases

2
Rational User Conference 2003 Group
IBM Software Rational software

Agenda

f Overview of the requirements types


f Traceability between requirements
f Actors and Use Cases
f How to create Test Cases from Use Cases
f Mapping to RUP
f Conclusions

Rational User Conference 2003 Group


IBM Software Rational software

What is traceability?
f A technique used to provide relationships between
requirements, design and implementation of a system in
order to manage the effect of change and ensure the
success of the delivered systems
f The ability to describe and follow the life of a requirement,
in both a forward and backward direction
f A technique allowing to determine the origins of any
requirement

3
Rational User Conference 2003 Group
IBM Software Rational software

Traceability of requirements

Needs

Features

Use Cases / Supp Spec

Scenarios

Test Cases

Rational User Conference 2003 Group


IBM Software Rational software

Role of traceability

f To verify that implementation fulfills requirements


ƒ Lower-level requirements are consistent with stakeholder needs
f To verify that the application does only what was intended
ƒ All functionality was requested
ƒ Only required testing was performed
f To help change management
ƒ Analyze impact of requirements change

4
Rational User Conference 2003 Group
IBM Software Rational software

What is a traceability item?


f Any project element that needs to be explicitly traced from
another textual or model item in order to keep track of the
dependencies between them
f With respect to RequisitePro: Any project element
represented within RequisitePro by an instance of a
RequisitePro requirement type
f Sample traceability items defined as requirement types in
RequisitePro:
ƒ Stakeholder Need
ƒ Feature
ƒ Use Case
ƒ Actor
ƒ Glossary Term

Rational User Conference 2003 Group


IBM Software Rational software

Showing traceability in RequisitePro

5
Rational User Conference 2003 Group
IBM Software Rational software

Agenda

f Overview of the Requirements Types


f Traceability between requirements
f Actors and Use Cases
f How to create Test Cases from Use Cases
f Mapping to RUP
f Conclusions

Rational User Conference 2003 Group


IBM Software Rational software

Use Cases and Actors

f Use Case: A description of system


behavior, in terms of sequences of
actions. A use case should yield an
observable result of value to an actor. Use Case
A use case contains basic flow and all
related alternate flows of events.

f Actor: Someone or something


external that interacts with the system.
Actor

6
Rational User Conference 2003 Group
IBM Software Rational software

Characteristics of a Use Case


f Is initiated by an actor to invoke functionality
f Models an interaction between an actor and the system
f Describes sequence of actions or related steps
f Captures functional requirements
f Provides value to the actor
f Is a complete and meaningful flow of events from the
perspective of a particular actor

Rational User Conference 2003 Group


IBM Software Rational software

ABC of writing effective Use Cases

f Address functionality
f Briefness in narrative
f Communicate effectively

(By Anand Maharana)

7
Rational User Conference 2003 Group
IBM Software Rational software

What is a purpose of Use Cases?


f To agree with the customers and users on what the
system should do
f Basis for Use Case realizations that play major role in the
design
f May be almost directly used for documentation
f Basis for planning the technical content of iterations
f Give system developers a better understanding of the
purpose of the system
f Can be used as an input for Test Cases

Rational User Conference 2003 Group


IBM Software Rational software

Use Case Diagrams

Canc el an order
Check order status
Place an order

Customer

8
Rational User Conference 2003 Group
IBM Software Rational software

Use Case format


1. Brief Description
2. Flow of Events
1. Basic Flow
2. Alternative Flow 1
3. Alternative Flow 2
3. Special Requirements
4. PreConditions
5. PostConditions
6. Extension Points
7. Context Diagram
8. Activity Diagram

Rational User Conference 2003 Group


IBM Software Rational software

Use Case “Place an order”: Basic Flow


B1 User enters web site address in the browser.
System displays login page.
B2 User enters an email address and a password.
System confirms correct login, presents main page, and prompts for a search string.
B3 User enters search string – partial name of a book.
System returns all books matching search criteria.
B4 User selects a book.
System presents detailed information about a book.
B5 User adds the book to a shopping cart.
Shopping cart contents is presented to the user.
B6 User selects “proceed to checkout” option.
System asks for confirmation of a shipping address.

9
Rational User Conference 2003 Group
IBM Software Rational software

Use Case “Place an order”: Basic Flow


B7 User confirms shipping address.
System presents shipping options.
B8 User selects shipping option.
Systems asks which credit card will be used.
B9 User confirms credit card that is stored in the system.
System asks for final confirmation to place an order.
B10 User places the order.
System returns confirmation number.

Rational User Conference 2003 Group


IBM Software Rational software

Alternate Flow 1: “Unregistered user”


A1.1 Alternate flow begins after step B1 when user selects “Register now” option.
System prompts for required information: name, address, userid, password.
A1.2 User provides required information.
Systems confirms registration and presents login screen.
A1.3 Flow continues from step B2 of the Basic Flow.

10
Rational User Conference 2003 Group
IBM Software Rational software

Alternate Flow 2: “Invalid password”


A2.1 Alternate flow begins after step B1 when user enters userid and password.
When either userid or password are invalid, system returns an error message and
displays login page.
A2.2 Flow continues from step B2 of the Basic Flow.

Rational User Conference 2003 Group


IBM Software Rational software

Activity Diagram Is user No User registers A1 – unregistered user


registered?
Yes

User enters email


and password

A2 – invalid password
No
Is password
correct?
Yes

User enters
search criteria

No System displays
A3 – no books found
Is there at least
one selection? notification
Yes

System presents list of


selections

User selects a
No
title

System presents details


about selected book

A4 – declining a book
Does user want to
buy this book?
Yes

User adds the book to


a shopping cart

System displays
Shopping cart
A5 – continue shopping
Yes
Does user want to
continue shopping?

11
Rational User Conference 2003 Group
IBM Software Rational software

Activity Diagram User proceeds


t o checkout

No
Is shipping address the User enters new address
same as in previous order?
A6 – new address Yes

User confirms
address

User selects
shipping options

Does user want to use No User adds new credit card


A7 – new credit card same credit card? information

Yes
User confirms
the card

Yes User cancels


A8 – cancel order Does user want to
cancel the order? order
No
User confirms
order

System returns
confirmation number

Rational User Conference 2003 Group


IBM Software Rational software

Agenda

f Overview of the requirements types


f Traceability between requirements
f Actors and Use Cases
f How to create Test Cases from Use Cases
f Mapping to RUP
f Conclusions

12
Rational User Conference 2003 Group
IBM Software Rational software

Proposed format prepares generation of Test Cases

f Steps in a Use Case correspond to steps in Test Case


f Unique numbering makes referring steps easy
f Combining user’s input and system’s response in one step
f Activity diagram is a basis for scenario generation

Rational User Conference 2003 Group


IBM Software Rational software

What is a Scenario?

f Scenario describes one particular path through the flow of


events described in a Use Case
f Scenario is an instance of an Use Case

13
Rational User Conference 2003 Group
IBM Software Rational software

How to find all Scenarios


B

A1

A3

A2

A4

Rational User Conference 2003 Group


IBM Software Rational software

Description of Scenario

Scenario can be described by:


f A sequence of alternate flows
Example:
SC16: A2 A2 A6
f A sequence of steps that form a scenario
Example:
SC16: B1, A2.1, A2.2, A2.1, A2.2, B2, B3, B4,
B5, B6, A6.1, A6.2, B8, B9, B10

14
Rational User Conference 2003 Group
IBM Software Rational software

Infinite loops

A1

Rational User Conference 2003 Group


IBM Software Rational software

Scenarios for book ordering use case


No User registers
A1 – unregistered user
SC1 – B
Is user
registered?
Yes

User enters email


and password

SC2 – A1 Is password
correct?
No
A2 – invalid password
Yes

User enters
search criteria

SC3 – A2 Is there at least


one selection?
Yes
No System displays
notification

A3 – no books found
System presents list of
selections

SC4 – A3 User selects a


title

SC5 – A4 Sy stem present s detai ls


about selected book

No Does user want to


A4 – declining a book
SC6 – A5
buy this book?

Yes

User adds the book to


a shopping cart

SC7 – A6 System displays

A5 – continue shopping
Shopping cart

Yes Does user want to


continue shopping?
No

SC8 – A7 User proceeds


to checkout

Is shipping address the No User enters new

A6 – new address
same as in previous order? address

SC9 – A8 2(8+4) = 4096


Yes

User confirms
address

User selects

SC10 – A1, A2
shipping options

Does user want to use No User adds new credit card


same credit card? informat ion

SC11 – A3, A4 Yes

User confirms
t he card
A7 – new credit card
SC12 – A4, A5 Does user want to Yes User cancels
order
cancel the order?

No

SC13 – A3, A5 User confirms


order
A8 – cancel order
System returns
confirmation number

SC14 – A6, A7

SC15 – A7, A8

15
Rational User Conference 2003 Group
IBM Software Rational software

Create requirement type “Scenario”

Rational User Conference 2003 Group


IBM Software Rational software

Traceability from Use Cases to Scenarios

16
Rational User Conference 2003 Group
IBM Software Rational software

From Scenarios to Test Cases


f Identify variables for each Use Case step
f Identify significantly different options for each step
f Select options that should be tested
f Combine options to be tested into Test Cases
f Assign values to variables

Rational User Conference 2003 Group


IBM Software Rational software

Identify variables for each Use Case step


f B2 Enter e-mail address and password
ƒ email (string)
ƒ password (string)
f B3 Search a book
ƒ search sentence (string)
f B4 Select a book
ƒ books (list)
f B8 Select shipping option
ƒ shipping method

17
Rational User Conference 2003 Group
IBM Software Rational software

Identify significantly different options for each step


f Strings
ƒ regular john_smith@aol.com
ƒ empty
ƒ min allowed a@b.com
ƒ max allowed 12345678910@verylongdomainname.com
ƒ max + 1 012345678910@verylongdomainname.com
ƒ very big aaaaaaaaaaaaaaaaaaaaaaaaaaaa...
ƒ logically invalid john_smith@aol.xyz
f Characters
ƒ lowercase a
ƒ uppercase A
ƒ numeric 5
ƒ special #

Rational User Conference 2003 Group


IBM Software Rational software

Identify significantly different options for each step


f Numbers
ƒ regular
ƒ min
ƒ max
ƒ min - 1
ƒ max + 1
ƒ 0
ƒ Negative

f Search criteria
ƒ 1 element returned
ƒ many elements
ƒ no elements

18
Rational User Conference 2003 Group
IBM Software Rational software

Identify significantly different options for each step


f Single selection sets of items
ƒ each item selected once

f Multiple selection sets of items


ƒ one selection
ƒ no selection
ƒ many selections
ƒ all items selected

Rational User Conference 2003 Group


IBM Software Rational software

Select options that should be tested

f B1 email: regular, empty, 1, 50, 51, 257 char, no @


f B1 password: regular, empty, 5, 6, 10, 11, 257 char
f B2 search sentence: regular, empty, 1, 300, 301 char
f B3 books: first selection, last selection
f B6 shipping method: each method once

19
Rational User Conference 2003 Group
IBM Software Rational software

Combine options to be tested into Test Cases


email pwd search book add checkout shipping order

R R

E E R
5
1 5 E
F 3
50 6 1
L
2
51 10 300
1
L 11 301

I L

Rational User Conference 2003 Group


IBM Software Rational software

Combine options to be tested into Test Cases


email pwd search book add checkout shipping order

R R

R
5
1
F 3
50 6 1
L
2
10 300
1
Test Case 1
Test Case 2
Test Case 3
Test Case 4

20
Rational User Conference 2003 Group
IBM Software Rational software

Guidelines for combining options

Rules to select an option is step n:


f Take any option that was not used yet
f Take an option that was not used after the option selected
in step n-1
f Take an option that was used the least

Rational User Conference 2003 Group


IBM Software Rational software

Test Case matrix


Step Variable or TC1 TC2 TC3 TC4
selection
B1 Website Regular Regular Regular Regular
B2 Email Regular Min Max Regular
B2 Password Regular Min Max Min
B3 Search string Regular Min Max Regular
B4 Book selection First Last First Last
B5 Shopping chart Add Add Add Add
B6 Checkout Checkout Checkout Checkout Checkout
B7 Address Same Same Same Same
B8 Shipping option 1st 2nd 3rd 4th
B9 Credit card Same Same Same Same

21
Rational User Conference 2003 Group
IBM Software Rational software

Assign values to variables

Step Variable or Value Expected result Obtained result


number selection
B1 Website www.amazon.com Logon Screen
B2 Email Jsmith@hotmail.com -
B2 Password Johnsm Main Screen
B3 Search string “Rational” List of books
B4 Book selection First Book details
B5 Shopping chart Shopping chart Cart contents
B6 Checkout Checkout Prompt for address
B7 Address Same Prompt for shipping
B8 Shipping option 5 days Prompt for payment
B9 Credit card Same Prompt for confirmation

Rational User Conference 2003 Group


IBM Software Rational software

Traceability matrix

22
Rational User Conference 2003 Group
IBM Software Rational software

Traceability tree

Rational User Conference 2003 Group


IBM Software Rational software

Traceability tree

23
Rational User Conference 2003 Group
IBM Software Rational software

Traceability tree

Rational User Conference 2003 Group


IBM Software Rational software

Traceability tree

24
Rational User Conference 2003 Group
IBM Software Rational software

Suspect relationships

Rational User Conference 2003 Group


IBM Software Rational software

What is being tested

25
Rational User Conference 2003 Group
IBM Software Rational software

Rational User Conference 2003 Group


IBM Software Rational software

Agenda

f Overview of the requirements types


f Traceability between requirements
f Actors and Use Cases
f How to create Test Cases from Use Cases
f Mapping to RUP
f Conclusions

26
Rational User Conference 2003 Group
IBM Software Rational software

Where in the process does it fit?

Rational User Conference 2003 Group


IBM Software Rational software

Agenda

f Overview of the requirements types


f Traceability between requirements
f Actors and Use Cases
f How to create Test Cases from Use Cases
f Mapping to RUP
f Conclusions

27
Rational User Conference 2003 Group
IBM Software Rational software

Benefits of this approach


f Test Cases are derived in more automatic way
f Avoiding duplicate testing
f Better test coverage
f Easier monitoring of testing progress
f Easier work load balancing between testers
f Easier regression testing
f Decreasing project time by moving some tasks from
construction to elaboration
f Contribution to early discovery of missing requirements

Rational User Conference 2003 Group


IBM Software Rational software

Literature
f Jim Heumann, "From Use Cases to Test Cases - Ensuring
Quality from the Beginning." RUC 2001.
f Jim Heumann, "Using Use Cases to Create Test Cases."
The Rational Edge, June 2001.
f Dean Leffingwell and Don Widrig, “Managing Software
Requirements: A Unified Approach”. Addison-Wesley,
1999.
f Dean Leffingwell and Don Widrig, “The Role of
Requirements Traceability in System Development”,
The Rational Edge, September 2002.
f Rational Unified Process. Rational Software Corporation,
2001.

28
Rational User Conference 2003 Group
IBM Software Rational software

Rational User Conference 2003 Group


IBM Software Rational software

Peter Zielczynski, Ph.D.


PZielczynski@tact.com

29