You are on page 1of 7

FEATURE

In this article, we will discuss how


using use cases to generate test cases

Generating Test can help launch the testing process


early in the development life cycle and
also help with testing methodology.

Cases
by Jim Heumann

from Use Cases


n many organizations, software testing performed by a system to provide an specific test scripts.
accounts for 30 to 50 percent of soft- observable result of value to a person or
ware development costs. Yet often that another system using the product under • Test Script - The step-by-step
same software is delivered with signifi- development.” Use cases tell the cus- instructions that realize a test,
cant defects. This contradiction is root- tomer what to expect, the developer enabling its execution. Test Scripts
ed in two clear facts: First, testing soft- what to code, the technical writer what may take the form of either docu-
ware is a very difficult proposition; and to document, and the tester what to test. mented textual instructions that are
second, testing is typically done without executed manually or computer read-
a clear methodology. For software testing — which consists able instructions that enable automat-
of many interrelated tasks, each with its ed test execution.
A widely-accepted tenet in the industry own artifacts and deliverables — cre-
is that it is better to start testing as early ation of test cases is one of the first fun- Although few actually do it, testers can
in the software development process as damental steps. Then test procedures begin creating test cases as soon as use
possible. Delaying the start of testing are designed for these test cases, and cases are available, well before any
activities until all development is done finally, test scripts are created to imple- code is written. We will discuss how to
is a high-risk way to proceed. If signifi- ment the procedures. Test cases are key do this, and the advantages you can reap
cant bugs are found at that stage (and to the process because they identify and from it, below.
they usually are), then schedules often communicate the conditions that will be
slip. implemented in test and are necessary An Introduction to Use
to verify successful and acceptable Cases
Haphazard methods of designing, implementation of the product require- Use cases are part of the Unified
organizing, and implementing testing ments. They are all about making sure Modeling Language (UML) and can be
activities and artifacts also frequently that the product fulfills the require- visually represented in use-case dia-
lead to less-than-adequate test cover- ments of the system. grams. Figure 1 (on page 2) shows a
age. Having a straightforward plan for use-case diagram depicting require-
how testing is done can help increase • Test Case - A set of test inputs, exe- ments for a university course registra-
coverage, efficiency, and ultimately cution conditions, and expected tion system.
software quality. results (outputs) developed to verify
compliance with a specific require- The ovals represent use cases, and the
In a software development project, use ment stick figures represent “actors,” which
cases define system software require- • Test Procedure - The procedural can be either humans or other systems.
ments. Use case development begins aspect of a given test, usually a set of The lines represent communication
early on, so real use cases for key prod- detailed instructions for the setup and between an actor and a use case. As you
uct functionality are available in early execution of one or more given test can see, this use-case diagram provides
iterations. By definition, a use case “… cases. The test procedure is an the big picture: Each use case repre-
fully describes a sequence of actions abstract idea realized by one or more sents a big chunk of functionality that

September 2002 http://www.testinginstitute.com Journal of Software Testing Professionals 1


can be either humans or other systems.
The lines represent communication Feasibility
Study
between an actor and a use case. As you Test Strategy
can see, this use-case diagram provides Project
Definition
the big picture: Each use case represents
a big chunk of functionality that will be User Acc.
Test Plan
implemented, and each actor represents Ops. Accept.
Test Plan System
someone or something outside our sys- Test Plan Integration
tem that interacts with it. Test Plan Unit
It is a significant step to identify use Test Plan
cases and actors, but now there is more
to be done. Each use case also requires Requirements Operational System Design Detailed Design
Definition Requirements Document Document
a significant amount of text to describe
it. This text is usually formatted in sec-
tions, as shown in Table 1. KEY
Development
Unit
Use Case Section Description Name An Deliverable Integration Test Spec.
appropriate name for the use case Brief System Test Spec.
Testing Ops. Accept. Test Spec.
Description A brief description of the User Acc.
Deliverable Test Spec.
use case’s role and purpose. Flow of Test Spec.
Events A textual description of what the
actor does and what the system does in
response. There will always be one
main flow and there will usually be
requirements specific to the use case. conditions A textual description that
multiple alternate flows. The descrip-
Preconditions A textual description that defines any constraints on the system at
tion should be understandable to the
defines any constraints on the system at the time the use case will terminate.
customer. Special Requirements A tex-
the time the use case may start. Post The most important part of a use case
tual description of non-functional
for generating test cases is the flow of
events. The two main parts of the flow
Table 1: Format for a Use-Case Textual Description
of events are the basic flow of events
Use Case Section Description and the alternative flows of events. The
Name An appropriate name for the use case basic flow of events should cover what
“normally” happens when the use case
Brief Description A brief description of the use case’s role and pur- is performed. The alternative flows of
pose events covers behavior of an optional or
exceptional character relative to normal
Flow of Events A textual description of what the actor does and- behavior, and also variations of the nor-
what the system does in response. There will mal behavior. You can think of the alter-
always be one main flow and there will usually be native flows of events as “detours” from
multiple alternative flows. The description should the basic flow of events.
be understandable to the customer.
Figure 2 represents the typical structure
Special Requirements A textual descsription of non-functional require- of these flows of events. The straight
ments specific to the use case. arrow represents the basic flow of
events, and the curves represent alter-
Preconditions A textual description that defines any constraints nate flows. Note that some alternate
on the system at the time the use case may start. flows return to the basic flow of events,
while others end the use case. Both the
Post conditions A textual description that defines any constraints basic flow of events and the alternative
on thesystem at the time the use case will termi- flows should be further structured into
nate. steps or subflows.

2 Journal of Software Testing Professionals http://www.testinginstitute.com September 2002


Use-Case Scenarios
There is one more thing to describe
before we concentrate on how use cases
can be used to generate test cases: a use-
case scenario. A use-case scenario is an
instance of a use case, or a complete
“path” through the use case. End users
of the completed system can go down
many paths as they execute the func-
tionality specified in the use case.
Following the basic flow would be one
scenario. Following the basic flow plus
alternate flow A1 would be another. The
basic flow plus alternate flow A2 would
be a third, and so on.

Table 2, on the next page, lists all possi-


ble scenarios for the diagram shown in
Figure 2, beginning with the basic flow
and then combining the basic flow with
alternate flows.

A textual description for the basic flow of events in the Register For Courses Use Generating Test Cases
Case is shown in Figure 3. A test case is a set of test inputs, execu-
tion conditions, and expected results
Figure 3: Textual Description for the University Course Registration Use- developed for a particular objective: to
Case Basic Flow of Events exercise a particular program path or
verify compliance with a specific
Register For Courses requirement, for example.
Basic Flow
The purpose of a test case is to identify
1. Logon and communicate conditions that will
This use case starts when a Student accesses the Registration System. be implemented in test. Test cases are
The system asks for, and the Student enters, the student ID and password. necessary to verify successful and
2. Select ‘Create a Schedule’ acceptable implementation of the prod-
The system displays the functions available to the student. The student uct requirements (use cases).
selects “Create a Schedule.”
3. Obtain Course Information We will describe a three-step process
The system retrieves a list of available course offerings from the Course for generating test cases from a fully-
Catalog System and displays the list to the Student. detailed use case:
4. Select Courses
The Student selects 4 primary course offerings and 2 alternate course offer- 1. For each use case, identify a full set
ings from the list of available course offerings. of use-case scenarios.
5. Submit Schedule 2. For each scenario, identify at least
The student indicates that the schedule is complete. For each selected course one test case and the conditions that
offering on the schedule, the system verifies that the Student has the neces- will make it “execute.”
sary prerequisites. 3. For each test case, identify the data
6. Display Completed Schedule values with which to test.
The system displays the schedule containing the selected course offerings
for the Student and the confirmation number for the schedule. Step One: Generate
Scenarios

September 2002 http://www.testinginstitute.com Journal of Software Testing Professionals 3


Figure 4: Textual Description for University Course Registration Use-Case Step Two: Identify Test
Alternate Flows Cases
Once the full set of scenarios has been
Register for Courses identified, the next step is to identify the
Alternate Flows test cases. We can do this by analyzing
the scenarios and reviewing the use
A1. Unidentified Student case textual description as well. There
In Step 1of the Basic Flow, Logon, if the system determines that the should be at least one test case for each
student ID and/or password is not valid, an error message is displayed. scenario, but there will probably be
A2. Quit more. For example, if the textual
The Course Registration System allows the student to quit at any time dur- description for an alternate flow is writ-
ing the use case. The Student may choose to save a partial schedule before ten in a very cursory way, like A3.
quitting. All courses that are not marked as “enrolled in” are marked as Unfulfilled Prerequisites, Course Full,
“selected” in the schedule. The schedule is saved in the system. The use case or Schedule Conflicts, shown above,
ends. then additional test cases may be
A3. Unfulfilled Prerequisites, Course Full, or Schedule Conflicts required to test all the possibilities. In
In Step 5, Submit Schedule in the Basic Flow, if the system determines that addition we may wish to add test cases
prerequisites for a selected course are not satisfied, that the course is full, or to test boundary conditions.
that there are schedule conflicts, the system will not enroll the student in the
course. A message is displayed that the student can select a different course. The next step in fleshing out the test
The use case continues at Step 4, Select Courses, in the basic flow. cases is to reread the use-case textual
A4. Course Catalog System Unavailable description and find the conditions or
In Step 3, Obtain Course Information in the Basic Flow, if the course cata- data elements required to execute the
log system is down a message is displayed and the use case ends. various scenarios. For the Register for
A5. Course Registration Closed Course use case, conditions would be
If, when the use case starts, it is determined that registration has been closed student ID, password, courses selected,
a message is displayed and the use case ends. etch.

As you can see, a significant amount of detail goes into fully specifying a use case. To clearly document the test cases, once
Ideally, the flows should be written as “dialogs” between the system and the again, a matrix format is useful, like the
actors. Each step should explain what the actor does and what the system does in one in Table 4. Notice the top row. The
response; it should also be numbered and have a title. Alternate flows always first column contains the test case ID,
specify where they start in the basic flow and where they go when they end. the second column has a brief descrip-

Table 2: Some scenarios for the “use case” shown in Figure 2


Scenario ID Starting Flow First Alternate Flow Second Alternate Flow Third Alternate Flow

Scenario 1 Basic Flow

Scenario 2 Basic Flow

Scenario 3 Basic Flow Alternate Flow 1 Alternate Flow 2

Scenario 4 Basic Flow Alternate Flow 3

Scenario 5 Basic Flow Alternate Flow 3 Alternate Flow 1

Scenario 6 Basic Flow Alternate Flow 3 Alternate Flow 1 Alternate Flow 2

Scenario 7 Basic Flow Alternate Flow 4

Scenario 8 Basic Flow Alternative Flow 3 Alternate Flow 4

You can see that a scenario always starts in the basic flow, and besides the basis flow itself, always exercises one ore more
alternate flows. These scenarios will be used as the basis for creating test cases.

September 2002 http://www.testinginstitute.com Journal of Software Testing Professionals 9


Table 3: Partial Scenario Matrix for the Register for Courses Use Case
Scenario ID Starting Flow First Alternate Flow Second Alternate Flow
1 - Successful registration Basic Flow
2 - Unidentified student Basic Flow
3 - User Quits Basic Flow A1
4 - Course registration system unavail. Basic Flow A2
5 - Registration closed Basic Flow A4
6 - Course full Basic Flow A3
7 - Prerequisite not fulfilled Basic Flow A3
8 - Schedule conflict Basic Flow A3
9 - Schedule conflice & User Quits Basic Flow A3 A2

Table 4: Test Case Matrix for the Register for Courses Use Case
Test Scenario/ Student Courses Pre-Req’s Course Schedule Expected
Case ID Condition ID Password Selected Fulfilled Open Open Result
RC 1 Scenario 1 - V V V V V V Schedule and
successful confirmation
registration number displayed.
RC 2 Scenario 2 - I N/A N/A N/A N/A N/A Error message -
unidentified back to login
student screen
RC3 Scenario 3 - V V N/A N/A N/A N/A Login screen
valid user quits appears
RC4 Scenario 4 - V V N/A N/A N/A N/A Error message -
course regi- back to step 2
stration system
unavailable
RC 5 Scenario 5 - V V N/A N/A N/A N/A Error message -
registration back to step 2
closed
RC6 Scenario 6 - V V V V I V Error message -
cannot enroll - back to step 3
course full
RC 7 Scenario 7 - V V v I V V Error message -
cannot enroll - back to step 4
pre-requisite
not fulfilled
RC 8 Scenario 8 - V V V V V I Error message -
cannot enroll - back to step 4
schedule conflict
RC 9 Scenario 9 - V V V V V I Error message -
schedule conflict use case ends
and user quits

tion of the test case, including the sce- Notice that in this matrix no data values clearly shows what conditions are being
nario being tested, and all other have actually been entered. The cells of tested for each test case. It is also very
columns except the last one contain the table contain a V, a I or n/a. V indi- easy to determine by looking at the Vs
data elements that will be used in imple- cates valid, I is for invalid and n/a and Is whether you have identified a
menting the tests. The last column con- means that it is not necessary to supply sufficient number of test cases. In addi-
tains a description of the test case’s a data value in this case. This specific tion to the “happy day” scenarios in
expected output. matrix is a good intermediate step; it which everything works fine, each row

10 Journal of Software Testing Professionals http://www.testinginstitute.com September 2002


Table 5: Test Case Matrix with Data Values
Test Scenario/ Student Courses Pre-Req’s Course Schedule Expected
Case ID Condition ID Password Selected Fulfilled Open Open Result
RC 1 Scenario 1 - jheumann abc123 M101 Yes Yes Yes Schedule and
successful E201 confirmation
registration S101 number displayed.
RC 2 Scenario 2 - Jheuman1 N/A N/A N/A N/A N/A Error message -
unidentified back to login
student screen
RC3 Scenario 3 - jheumann abc123 N/A N/A N/A N/A Login screen
valid user quits appears
RC4 Scenario 4 - jheumann abc123 N/A N/A N/A N/A Error message -
course regi- back to step 2
stration system
unavailable
RC 5 Scenario 5 - jheumann abc123 N/A N/A N/A N/A Error message -
registration back to step 2
closed
RC6 Scenario 6 - jheumann abc123 M101 Yes M101full Yes Error message -
cannot enroll - E201 back to step 3
course full S101
RC 7 Scenario 7 - jheumann abc123 M101 No for E201 Yes Yes Error message -
cannot enroll - E201 back to step 4
pre-requisite S101
not fulfilled
RC 8 Scenario 8 - jheumann abc123 M101 Yes Yes E202 and Error message -
cannot enroll - E201 S101 conflict back to step 4
schedule conflict S101
RC 9 Scenario 9 - jheumann abc123 M101 Yes Yes E202 andI Error message -
schedule conflict E201 S101 conflict use case ends
and user quits S101

in the matrix should have at least one I implemented or executed; they are just Using the clearly-defined methodology
indicating an invalid condition being descriptions of conditions, scenarios, I’ve outlined above for generating test
tested. In the test case matrix in Table 4, and paths. Therefore, it is necessary to cases, testers and developers can sim-
some conditions are obviously missing identify actual values to be used in plify the testing process, increase effi-
— e.g., Registration Closed — because implementing the final tests. Table 5 ciency, and help ensure complete test
RC3, RC4 and RC5 each have the same shows a test case matrix with values coverage.
combination of Is and Vs. Additionally, substituted for the Is and Vs in the pre-
each column should contain an I in at vious matrix. A number of techniques About the Author:
least one cell. Looking at the Password can be used for identifying data values, As Requirements Management Evan-
column in table 4 one can see that there including random or creative data entry, gelist at Rational Software, Jim
is no I, this indicates that a test case is but these are beyond the scope of this Heumann specializes in the front end of
missing, there is no test for a bad pass- article. the software development lifecycle. Jim
word. This “intermediate” test matrix, has been with Rational software for
thus, helps to quickly analyze test cov- Putting It All Together over two years, most of which has been
erage for the associated use case. In current practice, use cases are associ- spent helping customers understand and
ated with the front end of the software implement software processes and
Step Three: Identify Data development lifecycle and test cases are tools.
Values to Test typically associated with the latter part
Once all of the test cases have been of the lifecycle. By leveraging use cases Heumann has been in the software busi-
identified, they should be reviewed and to generate test cases, however, testing ness since 1982, having worked on
validated to ensure accuracy and to teams can get started much earlier in the analysis, development, design, training
identify redundant or missing test cases. lifecycle, allowing them to identify and and project management in several
Then, once they are approved, the final repair defects that would be very costly organizations of various sizes and
step is to substitute actual data values to fix later, ship on time, and ensure that industry segments.
for the Is and Vs. Without test data, test the system will work reliably.
cases (or test procedures) can’t be

September 2002 http://www.testinginstitute.com Journal of Software Testing Professionals 11


Abstract application, we miss much of the under-
By reviewing this paper, the reader lying context and may ignore critical
should gain additional insight into the business constraints that will ultimately
following areas: determine our effort’s success or fail-
• The differences between functional ure. And just like a journalist who skips
and non-functional requirements one or more of his “Magic Five,” we
• The importance of non-functional often end up building software applica-
requirements during system analysis tions that seem unfinished and/or cause
and testing as many problems as they solve.
• The major categories of non-function-
al requirements Functional vs. Non-Functional
• The primary characteristics of each Requirements
non-functional requirement type Unfortunately for IT, software is not
• Suggested methods for integrating like Kevin Costner’s baseball diamond
non-functional requirements into soft- in the Hollywood motion picture “Field
ware testing practices of Dreams.” In the movie, Costner has a
vision which tells him that “If you build
Introduction it (the baseball diamond), they will
From an early age, we are all taught the come (ghostly players and real-life
basic questions to ask when gathering fans).” In software, on the other hand,
information. Whether you are a school just because we build it (the software),
child researching a report, a journalist it doesn’t mean they will come (the cus-
investigating a story, or a witness tomers).
recounting a crime scene, you immedi-
ately ask yourself the so-called “Magic Instead, it is our job to first determine
Five Questions.” These, of course, exactly what a customer needs before
include “Who,” “What,” “Where,” we begin building the solution. We do
“When” and “How.” And as every good this by asking the “What” questions,
journalist knows instinctively, without and the answers to those questions are
all of this information the resulting usually referred to in the IT world as the
work seems unfinished and/or raises as “functional requirements” for the appli-
many questions as it answers. cation.

For some reason, however, we IT pro- Functional requirements describe what


fessionals seem to forget these basic it is that a customer needs to be able to
investigative techniques when we do with our software. They may be doc-
attempt to define the requirements for a umented in the form of rigorously spec-
software application. As we interview ified process models or use cases, or
customers for their needs, we focus on they may simply be lists of required fea-
only one aspect; that is, the “What.” tures and functions. Whatever the form
Nearly all of the questions we ask used, functional requirements should
address what the customer wants to be always identify the minimum function-
able to do with the application, and we ality necessary for the software imple-
assume that if we deliver everything the mentation to be considered a success.
customer asked for then our application
will be a success. However, as mentioned earlier, this is
not enough. Instead, business analysts
Unfortunately, this assumption is bla-
tantly inaccurate. It is just as important
to ask the remaining four questions as it
is to thoroughly document the first. By
focusing on only the “What” of the

12 Journal of Software Testing Professionals http://www.testinginstitute.com September 2002

You might also like