Use Case Testing – The Complete Guide
Use case testing is one of the black box testing techniques used for functional testing of the developed system in order to find any defects. It uses test cases that are created based on the use cases to test the system.
As use cases are written before the development process starts. A testing team can take the help of the use case document to create test cases. These test cases can be used in system testing, regression testing, sanity testing, acceptance testing, etc.
Before we start with the use case testing in detail, let’s first understand ‘Use Case’ in brief.
Content
What is a Use Case?
A use case is a list of actions taken by the actor while interacting with the system to achieve a goal. Here, an actor can be anyone who is using the system either human or any external system. Use cases are used to describe the functional requirements of the system.
Functional requirements are written by the Business Analyst after the requirements gathering and analysis phase, and before the designing and coding phases. That is before the development team starts working on the system.
Use Case Example
Let’s take an example of one simple use case of a customer placing an order in an e-commerce application. A typical use case has the following structure-
Use Case ID | UC 001 |
Use Case Name | Place Order |
Actors | Customer |
Brief Description | This use case explains the steps using which the customer can place an order on the application. |
Navigation | Login-> Search for a product-> Click on ‘Add to Cart’ button-> Click on ‘Go to Cart’ button-> Select Quantity-> Click on ‘Place Order’ button |
Pre-conditions | The customer has added the product in the cart and selected the quantity. The customer has indicated that s/he wants to place an order by clicking on the ‘Place Order’ button. |
Post-conditions | The order should be placed. |
Main/Normal Flow | The customer clicks on the ‘Place Order’ button.The customer will be displayed the ‘Contact Details and Address’ screen to enter the contact details and the address.The customer enters the contact details and address and clicks on the ‘Submit’ button.The customer will be displayed the ‘Order Summary’ screen to view the order summary.The customer confirms the order and clicks on the ‘Confirm and Pay’ button.The customer will be displayed the ‘Payment’ screen to complete the payment.The customer selects the ‘Credit Card’ payment method and enters credit card details to complete the payment.The confirm message will be displayed to the customer along with ‘Order ID’ after successful payment. |
Alternative Flow | 1AF 1: If the customer is not logged in, s/he will be asked to log in to the system first. The customer clicks on the ‘Place Order’ button.The customer will be taken to the ‘Login/Register’ page.The customer clicks on the ‘Login’ button.The customer enters the username and password.The customer clicks on the ‘Login’ button.The customer logs in.< 5AF 1: If the customer wants to change the quantity, s/he can go back to change the quantity and then proceed with the order placing process. The customer clicks on the ‘Back’ button.The customer will be taken to the ‘Contact Details and Address’ screen.The customer clicks on the ‘Back’ button.The customer will be taken to the ‘Product Details’ screen.The customer changes the quantity.The customer clicks on the ‘Place Order’ button.< 5AF 2: If the customer wants to change the contact and address information, s/he can go back to change the details and then proceed with the order placing process. The customer clicks on the ‘Back’ button.The customer will be taken to the ‘Contact Details and Address’ screen.The customer changes the details.< 7AF 1: If the customer wants to cancel the order, s/he can cancel the order and go back to the homepage. The customer clicks on the ‘Cancel’ button.The customer will be displayed a confirm pop up window with ‘Yes’ and ‘No’ button.The customer clicks on the ‘Yes’ button.The customer will be taken to the home page. |
Exceptions | If the payment is unsuccessful, the customer will be displayed ‘Payment Unsuccessful’ message and will be taken to the ‘Order Summary’ page. |
Business Rules | <
|
Apart from above-mentioned sections, a use can have ‘Extended Use Cases’ section to mention any use case that follows after this use case, ‘Assumptions’ section to mention any assumptions that have been taken into consideration for this use case, ‘Wireframe’ section to show user interface related to the use case, etc.
In the above use case, just to keep the discussion short, we have assumed that credit card is the only payment method available in the system and, not every possible alternative flow is mentioned here.
As we can see in the above structure, a use case details the steps taken by a user to complete the action of placing an order, a user goal of placing an order. It also mentions any alternative flows and exceptions that can arise while achieving the goal.
Now let’s look at the test cases that can be designed using this use case.
How to create test cases from use cases?
For each possible flow in the use case, a separate test case should be created. In the above example, five paths or flows are mentioned (One Main/Normal Flow and Four Alternative Flows). So at least five test cases should be designed for the above example. If required, more than five test cases can be created. The important thing here is to cover each possibility. Note that even for exceptions, test cases will have to be designed.
While creating test cases from a use case, the following steps can be followed:
- The first step in the test case creation is to study the use cases and understand all the possible paths or flows of the use case.
- The second step is to identify all the test cases for each flow.
- The third step is to identify the test data for each test case.
Test Case Example
For this discussion, let’s focus on Main/Normal Flow. Following is the structure of a test case explained with the example of Normal Flow mentioned in the above use case:
Test Case ID | TC 001 |
Use Case ID | UC 001 |
Priority | High |
Description | This test case tests the normal flow of the customer placing an order. The customer after logging in and adding the item to the cart clicks on the ‘Place Order’ button to place an order. The customer enters contact details and address. The customer will verify the order details and go to the payment page. The customer will do the payment and after successful payment, an order will be placed. |
Pre-requisites | The user should have clicked on the ‘Place Order’ button in the cart. |
Steps | Click on the ‘Place Order’ button.Enter contact details and address in the fields mentioned below:<
|
Test Data | < |
Expected Result | The customer should be taken to the ‘Contact Details and Address’ page.The customer should be able to enter values as mentioned in the test data.The contact details and address should be saved, and the customer should be taken to the ‘Order Summary’ page.The customer should be taken to the payment page.The customer should be able to select the ‘Credit Card’ payment method and related fields should be displayed.The customer should be able to enter values as mentioned in the test data.The payment should be successful and a confirm message ‘Your payment has been successful, and the order has been placed. Your Order ID is XYZ1234’ should be displayed. |
For each step of the test case, expected result should be included.
To view the detailed format of a test case, kindly refer to our tutorial on – Test Case Template.
Now, let’s look at some advantages and disadvantages of using the use case testing type.
Advantages of Use Case Testing
- Use cases are designed from the user’s perspective; actions taken by the user while interacting with the system. So, the use case testing type focuses on the user; testing is done from the user’s perspective. As the testing team is thinking from the user’s perspective, it also helps them in identifying any issues related to the user experience.
- As test cases are designed based on the use cases, this testing type helps in covering all the possible flows that the actors are likely to take.
- While designing the test cases, as use cases are the base and the use case document is available before development starts, the testing team can start working on the test cases quickly and it also reduces the time involved in the test case design.
- Every use case is written with pre-conditions, post-conditions, business rules, normal flow, alternative flows, exceptions, etc. These sections help the testing team while designing the test cases.
- The complexity of the test cases can be reduced as the testing team will follow paths or flows given in the use case document.
Disadvantages of Use Case Testing
- If any flow or use case is missing in the use case document, it will also have an impact on the testing process as it is highly possible that the test cases for the missing use cases will be left out.
- Use cases cover only the functional requirements. The testing of non-functional requirements may not be possible.
- Use cases are written from the user’s perspective. There may be some scenarios in the system that are not from the user’s perspective, and they might not have been included in the use case document. In such cases, 100% test coverage of each system feature is not possible.
Conclusion
Use case testing is a testing type that uses test cases that are based on the use cases. It is a functional testing type and one of the black box testing methods. It helps in testing the system from the user’s perspective.