home

Use cases versus Test Cases

My company is experimenting with using Use Cases and Test Cases for documenting requirements, both function requirements and non-functional requirements. Previous, our requirements model had a Business Analyst gathering high level business requirements and a Systems Analyst creating a design document (functional level requirements) from the original and presenting it to an engineer. This was done in a linear fashion.

Going forward we are planning to use a more iterative approach and less waterfallish than mentioned above with a Srategy Analyst working upfront with a Busniess Case (feasibility, monetary impact, etc.) and the Business Analyst working in parallel with gather requirements and presenting them as gathered in Use Case and Test Case format.

What I want to hear from people is the definition of a Use Case versus the definition of a Test Case, and to what level of detail do each of them go.

For comparison sake, I will include my own interpretation. The way I understand things a Use Case is a high level scenario that describes how a user interacts with a system. These scenarios are represented by a stick man and a process box. In a Use Case there is a description, list of actors, flow of events, preconditions, post conditions and next steps. A Test Case would then be a list of Use Cases with specific details about function, design, texture and would lay out all possible scenarios for sunny days and rainy days (positive and negative outcomes).

For example, given the Scenario, Man wants money from an ATM, the following would be true:

Use Case, Man wants money from ATM
Use Case 1: Insert Card
Use Case 2: Enter PIN
Use Case 3: Choose withdraw option
Use Case 4: Take money
Use Case 5: Take receipt

Test Case 1: How to properly enter card or how to properly slide card.
Test Case 2: PIN number validation, if incorrect, fail
Test Case 3: Balance verification, if incorrect fail

This new organizational shift at my present employer has opened a great opportunity for me, and thus I would like to share my thoughts with the community and hopefully get some valuable feedback in the process.

Thanks!
Craig Cunningham
Business Analyst III

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Use Case vs Test Case

I am pro UML. It is the method of choice for me. In short, UML is a method of documentation, a language consisting of graphics and text. The graphics are the diagrams, and there are many, each used in practice for a different purpose. The text is the use cases (words).

My approach - I generally use Use Case Diagrams, Activity Diagrams and State Diagrams in my documentation of requirements as well as use cases. I level set with the Use Case Diagram and prepare one or more use cases to support the diagram.

The use case, as you stated, represents the user interaction. This can be done at different level, high level and more detailed levels. The use case format itself, as you probably know, are many. The format I use is very basic and for the most part suits the needs of my projects, and more importantly my end users of the documents (both business and IT developers).

The difference between a use case and a test case is as follows:

A use case will describe the preconditions, the basic flow, extensions and special requirements. A test case is built from the use case. I find it is generally a one to many relationship. As a matter of fact, multiple test cases can be built from one use case. How? For instance, if the test cases is about accessing an application, and it can be access at the office or remotely from home, you would want to include in your testing both means.

I believe UML, if used properly is the method of choice for developers and. It is hard to type everything out, but, feel free to contact me if you need any clarification.

Use Case vs Test Case

Typically a Test Case will be more detailed than a Use Case. That is, for a software requirement, the Use Case would specify the normal and alternate cases from a business users perspective. Whereas a Test Case, typcially not prepared by a BA, but a Tester, is prepared from the Use Case, but would include technical behind the scenes details that a business user may not care about, such as validating proper processing by middleware or the database. Both would indicate pre and post conditions.

Ideas and Definitions to Add Clarity to Use Case Discussion

Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4

/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin-top:0in; mso-para-margin-right:0in; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0in; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin;}

This is an interesting and wide ranging thread. I’d like to suggest some definitions and ideas that may help add clarity to the discussion.

I believe that part of the problem is that the UML Specification itself does not define terms well or, in some cases, not at all. Another issue is incorrect ideas about use cases have become repeated so many times that BAs believe they are true. I reference the Great BA fallacies #2: proof by verbosity posted at: http://businessanalysisonlinetraining.blogspot.com/2008/11/great-ba-fallacies-2-proof-by-verbosity.html.

We have developed a methodology over years of experience that may add clarity in this discussion. We define a use case as:

A use case is a set of interactions with a system
that provides a perceivable benefit of value
to someone or something (the user)
playing the use case's role (or part)
from the perspective of the user.

The three fundamental concepts, discussed individually, are:

A.     use case

B.     system

C.     role - yes, role and not actor

A.     Industry wide the use case concept is fairly well understood. It represents functionality that produces a benefit that is perceivable by the user. It describes how a user and a system behave to accomplish the defined goal.

 

B.     The concept of system is more problematic. The most serious problem is that system is typically a synonym for "the thing we are building." Several sub-problems are:

1.      Somehow the term system was hijacked by the IT community. For example, there are "business requirements" and "system requirements." The implication is that if it is not in code it cannot be a system. But businesses have had systems for centuries - long before IT automation existed.

2.      It is a problem that a system is thought of as a simple thing. We have never worked on a simple single system. Every project has been a system of systems.

 

In our methodology, we apply use cases for systems at any level of abstraction – so long as the behavior of the system that owns the use case is explicitly defined. The level can be the top level business system, the top level of an automated system, automated subsystems, component-to-component communication or even SOA services.

3.      The UML Specification does not give a useful definition of system. It says “A top-level subsystem in a model” which is not very helpful. A system is a subsystem?!?!

We have to go outside of the UML Specification to get a definition that applies to both business and IT. The best I’ve found is “a system is a set or group of elements that exhibit behavior collectively.” Note the emphasis on producing behavior. Without behavior, there is no system!

C.     Using roles is the biggest conceptual change that our methodology introduces. It is hard to know that roles even exist from many of the UML books that are available. However, the concept of role has been in the UML Specification all along.

Here is one excerpt. An actor is a “coherent set of roles ... An actor has one role for each use case with which it communicates.”

However, the concept of role has usually been ignored – with dire consequences.

I am happy that kmatthews mentioned the difference between roles and people in the thread.

An interesting question is, who owns a role? The short answer is there is a one-to-one mapping between a use case and a role. Additionally, the use case owns its role.

Rather than reproduce it here, I refer you to: building-requirements-consensus.com/use-case-basics.html for a detailed discussion of these three fundamental concepts.

This page is followed up with a yearlong case study, called UC Role Case Study, of a financial Transaction Auditing Program that was put into production. It was then changed twice before a third change request was made. At that point, I applied the methodology to find the real requirement.

The root cause of the thinking that led to the initial faulty requirements was using use case actors in the “industry standard” way. The case study shows how and why using roles instead of actors leads to better requirements that result in applications that satisfy, or even delight, your customers.

Sorting Out Levels of Abstraction

Some of this thread could be described as sorting out levels of abstraction, in particular, between use cases and tests. This is usually ambiguous because the multiple system boundaries at various levels of abstraction are not denoted. As a result, use cases that should belong in different systems end up on the same diagram. Visuals are powerful. Wrong visuals lead us to think incorrectly because of what we are seeing. Then we write incorrect use case steps and try to hold it all together.

To make matters worse, in the industry standard approach, the same actor is said to interact with these use cases without ever documenting the roles being played – even though the use cases belong to different systems at different levels of abstraction. Is it any wonder there is confusion on the functionality or the tests needed to validate it?

As a simple example of how the three fundamental ideas of the methodology, namely, use case, system & role, work together, consider an insurance company. It must handle claims:

1.      The processes within the claims department, a business system, that produce decisions about claims, can be described with a Handle Claim use case with the role Claim Handler.

2.      An automated process, an IT system, to verify that a policy with the right coverage was in force on the date of the incident, can be described with a Verify Policy use case with the role Policy Verifier.

3.      A service in a service oriented architecture, a SOA system, that queries a database of policies, can be described in a Query Policy Database use case with the role Policy Database Queryer.

Each use case will have its steps written with a different level of detail. Someone or something playing a Policy Verifier will see more details than someone or something playing a Claim Handler. Tests written for these two use cases will necessarily have different levels of detail.

Typically multiple tests should be created for each individual function a use case describes to cover positive cases, negative cases, random user behavior ;-) and boundary conditions.

The incorrect repeated ideas I mentioned earlier include these two that are mentioned earlier in this thread:

1.      Use cases can have preconditions and postconditions – actually, they cannot

2.      An exception is an alternate path – they are two different kinds of things

Please see the website for detailed discussions of these ideas as they do not fit within the main theme of this comment. However, they are important because writing use cases is simplified when you think about them clearly.

Hopefully, the ideas and definitions presented here will add clarity as we continue to discuss these important topics.

UML Adoption and Usage Statistics?

Can you please point us to adoption statistics and usage of UML by developers? 

- Scott

Hi Craig, my understanding is

Hi Craig, my understanding is the same as yours. I assume you have kept the Test Cases simple / short because you want to highlight your point.

UC = TC

I think your Use Case would be more like this:
Use Case - Withdraw money from ATM (Happy path)
Step 1 - User inserts card
Step 2 - System checks that card was inserted properly
Step 3 - User enters PIN
Step 4 - System checks the entered PIN is correct
Step 5 - User selects withdraw option and amount
Step 6 - System checks there is sufficient funds
Step 7 - User takes money
Step 8 - User takes receipt

Then there could be
Alternate or Exception Flows:
Step 2a - if the card was inserted incorrectly...
Step 4a - if the PIN is incorrect...
Step 6a - if there is insufficient funds...
Step 6b - User cancels request...
etc..

Your Use Case can have as much (or as little) detail as your stakeholders want. But the Use Case should include the happy path as well as the Alternate Flows and Exception Flows. Then your Use Case (plus Alternate/Exception Flows) becomes the basis for your Test Case. You can add more details to the Test Cases (if needed - like enter PIN 3 times then fail; enter 4 digits, 6 digits, etc...). Again - this depends on the people who are using the Test Cases. How detailed do you want them to be? I have found that the more time you spend writing documentation, the more time you spending reviewing & revising the documentation, and the less time you spend actually getting the requirements or doing the testing. Write them only to the level that you actually need! You know the users - you know what they need.

A few recommendations for improving the use case

All steps of a use case should be externally observable. Steps 2, 4 and 6 ae not black box steps .. i.e. there is no way for an external observer to test that these steps took place.

The only way to test these functions is to follow the exception steps. I.e. Card inserted incorrectly, PIN was incorrect or insufficient funds.

Remember that a use case should be describing only externally observable behaviour.

Leslie.

I like Helen's use case as written

I do not see an issue with describing what the user does, then what the system does in response. A use case is a good place to do that.

 My view is that it is the *test case* that we should strive to explain things from the perspective of someone external to the system.

UC = Set of Test Cases

A Use Case contains a Happy Day flow and generally several other flows, both Alternates/Variations and Exceptions. This structure generates four basic kinds of end-to-end flow which form candidate Test Cases:

1) Happy Day all the way through to success.
2) A Variation, possibly with part of the Happy Day flow, leading to success.
3) Happy Day, an Exception, leading to recovery and return to Happy Day, leading to success.
4) Happy Day, an Exception which cannot be recovered from, leading to controlled failure (eg an error message, a controlled stop).

In addition, it is possible for more than one Exception to occur, and Exceptions may arise during Variations, so (as every tester knows) many possible Test Cases may need to be considered.

A Use Case is a set or family of related and overlapping candidate Test Cases. The amount of detail must depend on the nature of the Use Case and the stakeholders' needs.

Using a scenario section of a use case

Hi Craig,
When modeling use cases I like including the 'scenarios' section that's recomended by Kurt Bittner and Ian Spence in their book 'Use Case Modeling'(which I found a little hard to get into but has become my use case bible). In this section you try to think of all the real world variations that could apply to the use case in question. What are the things that could change, and if they did change what would should be the expected result? (This is also a good method of figuring out if you missed something, because if you don't know the expected result a little flag should go up and you should try to find out the answer.) This ties in perfectly with creating Test Cases, where an approach is to identify all the possible variables in the use case and their boundaries. IE if the system must apply a certain tax for RSP withdrawals that are under $5000 you test 4999.99 and then you test $5000. Another variable that could also change the outcome of this is scenario is the residency of the withdrawer, so that would lead to another scenario. So, you can document these yourself, or better yet, work with the tester as early as you can to figure them out. They should be able to shake up your thinking a bit.

I'd also suggest against thinking of use cases as 'high level'or just for users- they can be useful to developers, business stakeholders, report analysts,accountants,testers, trainers and support staff, not to mention providing useful documentation for legacy purposes.

Post new comment

*
*
The content of this field is kept private and will not be shown publicly.

*

© 2007 Requirements Networking Group All rights reserved. contact | advertise | privacy
Requirements Networking Group