Open In App

How to write Test Cases – Software Testing

Software testing is known as a process for validating and verifying the working of a software/application. It makes sure that the software is working without any errors, bugs, or any other issues and gives the expected output to the user. The software testing process isn’t limited to finding faults in the present software but also finding measures to upgrade the software in various factors such as efficiency, usability, and accuracy. So, to test software the software testing provides a particular format called a Test Case

This article focuses on discussing the following topics in the Test Case:



  1. What is a Test Case?
  2. Test Case vs Test Scenario.
  3. When do we Write Test Cases?
  4. Why Write Test Cases?
  5. Test Case Template.
  6. Best Practice for Writing Test Cases.
  7. Test Case Management Tools.
  8. Formal and Informal Test Case.
  9. Types of Test Cases.
  10. Example.

What is a Test Case?

A test case is a defined format for software testing required to check if a particular application/software is working or not. A test case consists of a certain set of conditions that need to be checked to test an application or software i.e. in more simple terms when conditions are checked it checks if the resultant output meets with the expected output or not. A test case consists of various parameters such as ID, condition, steps, input, expected result, result, status, and remarks.

Parameters of a Test Case: 



Test Case vs Test Scenario

Below are some of the points of difference between a test case and a test scenario:

Parameter Test Case Test Scenario
Definition A test case is a defined format for software testing required to check if a particular application/software/module is working or not. Here we check for different conditions regarding the same.  The test Scenario provides a small description of what needs to be performed based on the use case.                                                                                                      
Level of detailing Test cases are more detailed with several parameters.  Test Scenario provides a small description, mostly one-line statements.  
Action Level Test cases are low-level actions.  Test scenarios are high-level actions. 
Derived from Test cases are mostly derived from test scenarios. Test scenarios are derived from documents like BRS, SRS, etc.
Objective It focuses on “What to test” and “How to test”. It focuses more on ‘What to test”.
Resources required Test cases require more resources for documentation and execution. Fewer resources are required to write test scenarios.
Inputs It includes all positive and negative inputs, expected results, navigation steps, etc. They are one-liner statements.
Time requirement It requires more time compared to test scenarios. Test scenarios require less time.
Maintenance They are hard to maintain. They require less time to maintain.

When do we Write Test Cases? 

Test cases are written in different situations:

So, test cases are written in such cases, as test cases help in further development and make sure that we are meeting all the needed requirements. 

Why Write Test Cases?   

Test cases are one of the most important aspects of software engineering, as they define how the testing would be carried out. Test cases are carried out for a very simple reason, to check if the software works or not. There are many advantages of writing test cases:

Test Case Template

Let’s look at a basic test case template for the login functionality. 

Below is the table that shows the basic template of a test case:

Fields Description
Test Case ID Each test case should have a unique ID.
Test Case Description Each test case should have a proper description to let testers know what the test case is about.
Pre-Conditions Conditions that are required to be satisfied before executing the test case.
Test Steps Mention all test steps in detail and to be executed from the end-user’s perspective.
Test Data Test data could be used as input for the test cases.
Expected Result The result is expected after executing the test cases.
Post Condition Conditions need to be fulfilled when the test cases are successfully executed.
Actual Result The result that which system shows once the test case is executed.
Status Set the status as Pass or Fail on the expected result against the actual result.
Project Name Name of the project to which the test case belongs.
Module Name Name of the module to which the test case belongs.
Reference Document Mention the path of the reference document.
Created By Name of the tester who created the test cases.
Date of Creation Date of creation of test cases.
Reviewed By Name of the tester who reviews the test case.
Date of Review When the test cases were reviewed.
Executed By Name of the tester who executed the test case.
Date of Execution Date when the test cases were executed.
Comments  Include comments which help the team to understand the test cases. 

In the given template below it’s identifiable that the section from module name to test scenario is the header section while the table that lies below the test scenario (from test case ID to comments) is the body of the test case template.     

Here a test case template for login functionality has been created with its parameters and values. 

Test Case Template

Best Practice for Writing Test Case

There are certain practices that one could follow while writing the test cases that would be considered beneficial. 

  1. Simple and clear: Test cases need to be very concise, clear, and transparent. They should be easy and simple to understand not only for oneself but for others as well. 
  2. Maintaining the client/customer/end-user requirements must be unique: While writing the test cases, it’s necessary to make sure that they aren’t being written over and over again and that each case is different from the others. 
  3. Zero Assumptions: Test cases should not contain assumed data, and don’t come up with features/modules that don’t exist. 
  4. Traceability: Test cases should be traceable for future reference, so while writing it’s important to keep that in mind, 
  5. Different input data: While writing test cases, all types of data must be taken into consideration. 
  6. Strong module name: The module name should be self-explanatory while writing the test case.  
  7. Minimal Description: The description of a test case should be small, one or two lines are normally considered good practice, but it should give the basic overview properly. 
  8. Maximum conditions: All kinds of conditions should be taken into consideration while writing a test, increasing the effectiveness. 
  9. Meeting requirements: While writing the test case the client/customer/end-user requirements must be met.
  10. Repetitive Results: The test case must be written in such a way that it should provide the same result. 
  11. Different Techniques: Sometimes testing all conditions might not be possible but using different testing with different test cases could help to check every aspect of a software. 
  12. Create test cases with the end user’s perspective: Create test cases by keeping end-user in mind and the test cases must meet customer requirements.
  13. Use unique Test Case ID: It is considered a good practice to use a unique Test Case ID for the test cases following a naming convention for better understanding.
  14. Add proper preconditions and postconditions: Preconditions and postconditions for the test cases must be mentioned properly and clearly.
  15. Test cases should be reusable: There are times when the developer updates the code, then the testers need to update the test cases to meet the changing requirements.
  16. Specify the exact expected outcome: Include the exact expected result, which tells us what will be result of a particular test step.

Test Case Management Tools

Test management tools help to manage the test cases. These tools are automated tools that decrease the time and effort of a tester as compared to the traditional way. Some test case management tools include advanced dashboards, easier bug, and progress tracking as well as management, custom test case templates, integration of test cases, inviting guest testers, managing team requirements and plans, and much more.

Below are some of the test case management tools:

Formal and Informal Test Case

Types of Test Cases

Example

Below is an example of preparing various test cases for a login page with a username and password.

Unit Test case: Here we are only checking if the username validates at least for the length of eight characters.

Test Id Test Condition Test Steps Test Input       Test Expected Result Actual Result Status     Remarks      
1. Check if the username field accepts the input of thirteen characters. 1. Give input   geeksforgeeks            Accepts for thirteen characters. Accepts for thirteen characters. Pass  None 

Here it is only checked whether the passing of input of thirteen characters is valid or not. So since the character word ‘geeksforgeeks’ is entered then the test is successful it would have failed for any other test case.  

 Functionality Test case: Here it is checked whether the username and password both work together on the login click.

Test Id Test Condition Test Steps                                     Test Input                                                   Test Expected Result Actual Result Status       Remarks         
1. Check that with the correct username and password able to log in.

1. Enter the username 

2. Enter the password

3. Click on the login 

username: geeks for geeks

password: geeksforever                  

Login successful Login successful Pass None
2. Check that if with an incorrect username and password able to not login.

1. Enter the username

2. Enter the password

3. Click on the login 

username: geeksforgeeks

password: geekstogether   

Login unsuccessful Login unsuccessful    Pass None

Here it is being checked whether passing wrong and right inputs and if the login functionality is working or not, it’s showing login is successful for the right credentials and unsuccessful for the wrong ones, hence both tests have passed otherwise would have failed.

User Acceptance Test Case: Here the user feedback is taken if the login page is loading properly or not.

Test Id                                   Test Condition Test Steps                                     Test Input                                                   Test Expected Result Actual Result Status           Remarks       
1. Check if the loading page loading efficiently for the client.   1. Click on the login button.  None Welcome to the login page. Welcome to the login page. Fail The login page is not loaded due to a browser compatibility issue on the user’s side. 

Here it is being checked in by clicking on the login button if the page is loaded and the ‘Welcome to login page’ message is displayed. The test has failed here as the page was not loaded due to a browser compatibility issue, it would have loaded if the test had passed. 


Article Tags :