Use Case vs Test Case: Core Differences
By Sonal Dwivedi, Community Contributor - November 12, 2022
In the Software Testing landscape, Use Case and Test Case are the most crucial terms, and they are somehow related to each other. As these terms are related, they are often used interchangeably by software professionals unknowingly. However, it is important to understand these terms and know their difference for accurate use. This article focuses on explaining these two terms with examples, their advantages, and their differences.
What is a Use Case
In Software testing, the term “use case” is used to describe all the possible steps a user may perform to interact with the system. It allows you to chalk out all the possible techniques and how the end-user can use the application with a set of instructions to the system and the expected result of the interaction with the system. It is a list of actions or event steps typically defining the interactions between an actor and system to achieve a goal.
Use cases also help QAs understand the areas where errors could occur while interacting with the system and design features to solve those errors. A use case is a graphical representation of a document explaining the steps an actor should perform to test the system.
Depending on the complexity of the use case, each use case must contain the following combinations of elements:
- Actor: A single person or a group of people that interact with the system.
- System: A product/service/software under test.
- Goal: The successful user outcome.
- Stakeholder(s): A person, group, or company that is directly or indirectly involved in the project and who may affect or get affected by the outcome of the project.
- Primary Actor: A stakeholder who initiates an interaction with the system to achieve a goal.
- Preconditions: The state of a system and its environment that must be met before a specific test can be run.
- Triggers: Events that occur for a use case to begin.
- Basic Flow of Success Scenario: A Use case flow that demonstrates the ideal case in which nothing goes wrong.
Use Case Diagram
In the Unified Modelling Language (UML), a use case diagram is used to create a visual representation of an actual live system. By using specialized symbols (for Actors, use case) and connectors are required to create a use case diagram.
A use case is represented by its name in an oval, and the actor is represented by a stick figure with the name below. Each action between an actor and a use case is represented by a line.
The Use case diagrams help to define the basic flow of events in the system. This high-level diagram can help the entire scrum team to understand the system under test and to discuss and define workflows in the system.
Use case diagrams are mostly created by business analysts at the early stage. However, it can be employed at any stage of the software development process. This can help the team to think of all the possible scenarios a system can perform. It also helps to find if there is any scenario missing to be integrated.
Example of a Use Case
Assuming the use case of an online shopping system between a customer and seller through an online shopping application. Here’s what the Use Case Diagram would be like.
The above use case diagram depicts an Online shopping system consisting of two main actors: Customer and Seller. Six use cases are identified to explain the high-level functionality of the online shopping system.
A customer can view products, add products to cart, checkout, and place orders. A seller can view products, update existing product details and its price, and add/remove products from inventory.
Here, considering an online shopping scenario initiated by a customer, the following are the details of the elements involved.
- Actor: A Customer.
- Trigger: The customer wishes to purchase the items via an online shopping app.
- Precondition: Network should be available, and the app should be logged in.
- System: Online Shopping App.
- Goal: Complete purchase successfully.
- Stakeholder: App owner.
Best Practices to Create a Use Case
Here are some of the best practices to follow for creating a use case:
- In a use case, each step should exhibit an action.
- The number of use cases should be somewhere between five to ten for better understanding and less complexity.
- Avoid using if statements. if statement comes with an else statement, and employing this would create complexity and confusion. Instead, use verbs like validate and verify. (The system verifies the login is valid)
- Use case steps should be simple, short, and easy to understand.
- Do not include UI while creating use cases for any system. UI is bound to change in the Agile framework, and we would not be interested in updating the use case for any UI update.
- Use cases should show a high level of representation and should not include minor things of the system.
- Use cases should only explain the functional part of the system and should not include the design.
Advantages of Use Case
Creating a use case has many benefits, some of them are:
- Use case diagrams fall under the functional requirement documentation technique. It is used for defining and organizing functional requirements in a system.
- Use cases help ensure that the correct system is developed by capturing the requirements from the end user’s point of view.
- It is used to model the basic flow of events in a use case.
- It is used to visualize software designing at a high level. Large complex applications can be split into small modules.
- It is used to capture the core functionalities of a system.
- It is presented in a simple and non-technical language so that it is easily understood by stakeholders, customers, developers, and testers.
- As Use cases focus on the users of the system, not the system itself, real system needs can be identified earlier in the design process.
- Use cases could serve in later stages as a base for test case creation.
What is a Test Case
A test case is a document which has a set of conditions/ actions/ steps that are performed on the software application in order to verify the expected functionality of the feature under test. A test case is mostly used to validate whether the developed feature is working as per requirement or not. It is a first-level action that is derived from test scenarios.
A test case design comprises,
- Test Case Id (which should be unique)
- Test Case Description
- Test Data
- Steps to execute
- Expected Result
- Actual Result
- Test case Author
- Test case Executed by
- Date of execution
To write a test case, a QA requires basic writing skills, attention to detail, a good understanding of the application under test, and out of box thinking. A test case should be written in such a way that it can be executed by any testing team member.
Suppose person A is working as a tester and has written test cases for an application. Assuming, some days later. person A is out of the office, and there’s an urgent need to run the test cases. Then in such a case, if the test case is not written properly (no precondition, incomplete steps, incorrect test data), it cannot be executed by any other team except person A.
To avoid such dependency, the test case should be written properly, covering all the details.
Example of a Test Case
Assuming the use case of an online shopping system between a customer and seller through an online shopping application. Here are some of the test cases for the use cases mentioned in the previous section.
|Test Case Id||Test case description||Pre-conditions||Steps||Expected Result||Actual Result||Status|
|CUS_001||Verify products can be added to cart||Login to Customer App||1. From the home page add 2 products to cart.|
2. Click on the cart icon.
|1. “Add to cart” button text should be changed to “Added to cart”.|
2. Cart should have 2 products added.
|1. “Add to cart” button text changed to “Added to cart”.|
2. 2 products added to cart.
|CUS_002||Verify products can be checkout||1. Login to Customer App|
2. Add products to cart.
|1. Click on the cart icon.|
2. Click on checkout button
|1. Cart page should open.|
2. Products should be checked out and the checkout page should open.
|1. Cart page is opened.|
2. Products should be checked out and the checkout page is opened.
|CUS_003||Verify products can be ordered||1. Login to Customer App|
2. Add products to cart and checkout.
|1. Click on place order button||1. Add shipping address page should open.||1. The shipping address page should be opened.||Pass|
Read More: Test Cases for an ECommerce Website
Best Practices to create a Test Case
Here are some of the best practices to be followed while creating Test Cases:
- Test case should be simple and easy to understand so that any team member can execute it.
- Use assertive language while creating a test case (Go to the home page, Click on the Login button, Enter credentials, etc.)
- Test cases should be created by keeping the customer’s requirements in mind. In the end, you would need test cases that can be easily understood by the end users and meet their expectations.
- All the necessary steps should be added in a test case in the first place. Also, the author’s name should be added. In future, if there is any difficulty in understanding the steps, the respective author can be approached to fix the same.
- Test case id and test case description should be unique, which helps classify them in the bug tracking tool.
- Ensure all the requirements are mapped to the test case.
- Expected Result should have statements containing “should be”/ “must be”.
- Test case should be generic so that it can be reused.
- Test cases should always be peer-reviewed. If in case any requirement/ step or precondition in a test case is missing, it can be added, making the test suite robust.
Also Read: Understanding Test Case Management
Advantages of Test Case
- Writing test cases at the early stage helps to find gaps in the design.
- It ensures maximum test coverage.
- It can be reused for future releases. Any new team member can refer to this test case to execute it.
- If there is any feature added, adding a corresponding test case will ensure the test case is executed in all future releases, thereby scaling the test suite.
- It is used to showcase the overall health of the application.
- It helps improve the quality of software by giving true results.
Use Case vs Test Case
Use cases are designed in the requirement and design phase of the SDLC methodology. Use cases are used to explain and document the interaction that is required between the user and the system to accomplish the user’s task. They are created to help the development team understand the steps that are involved in accomplishing the user’s goals.
Once created, use cases can often be used to derive more detailed functional requirements for the new system.
Test cases are derived from the use case and used in the testing phase of the SDLC methodology. It is used to validate whether the AUT under test is working as per requirement or not.
Below are the differences between Use Case and Test Case in tabular format.
|Use Case||Test Case|
|A use case is a graphical representation of actions that describes the behavior of a system to do a particular task||Test Case is a document specifying a set of actions to be performed on the application under test to verify the expected functionality of the feature|
|To create a use case SRS (System Requirement Specification) is required||To write a test case preconditions, test data and steps are required|
|It is dependent on the requirement document||It is dependent on the use case|
|Business Analyst create use case by collecting the requirement||Tester/ QA Analyst create a test case by using use case|
|End user executes the use case||Testers executes the test case|
|The purpose of use case is to understand the end-user interaction with the system||The purpose of the test case is to validate whether that particular feature is functioning as expected or not.|
|The use case focuses on the end user||Test case focuses on the Test result|
|The result of the use case has not been verified||The result of a test case is verified with the expected result|
|Use case interacts with the user||Test case interacts with the result|
|Use case creation can be helpful in the requirement gathering, and design phase||Test case is executed in the testing phase|
While creating use cases and test cases it is important to consider real user conditions while testing to ensure that the applications function seamlessly in the real world. Hence, it is essential to not only design the use case and test case by keeping real user conditions in mind, but it is equally important to test on real devices over emulators and simulators for more accurate results.
Real device cloud like BrowserStack allows access to 3000+ real device browser combinations for comprehensive and thorough testing with features like geolocation testing, network simulation, QR code, and barcode testing.