The Wayback Machine - https://web.archive.org/web/20240930223827/https://www.geeksforgeeks.org/test-case/
Open In App

How to write Test Cases – Software Testing

Last Updated : 26 Sep, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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:

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:

  • Module Name: Subject or title that defines the functionality of the test.
  • Test Case Id: A unique identifier assigned to every single condition in a test case.
  • Tester Name: The name of the person who would be carrying out the test.
  • Test scenario: The test scenario provides a brief description to the tester, as in providing a small overview to know about what needs to be performed and the small features, and components of the test.
  • Test Case Description: The condition required to be checked for a given software. for eg. Check if only numbers validation is working or not for an age input box.
  • Test Steps: Steps to be performed for the checking of the condition.
  • Prerequisite: The conditions required to be fulfilled before the start of the test process.
  • Test Priority: As the name suggests gives priority to the test cases that had to be performed first, or are more important and that could be performed later.
  • Test Data: The inputs to be taken while checking for the conditions.
  • Test Expected Result: The output which should be expected at the end of the test.
  • Test parameters: Parameters assigned to a particular test case.
  • Actual Result: The output that is displayed at the end.
  • Environment Information: The environment in which the test is being performed, such as the operating system, security information, the software name, software version, etc.
  • Status: The status of tests such as pass, fail, NA, etc.
  • Comments: Remarks on the test regarding the test for the betterment of the software.

Just as a well-structured test case is essential for validating and verifying the functionality of software, gaining a deep understanding of software testing methodologies is crucial for ensuring the success of any testing process. If you’re looking to enhance your skills in creating and managing test cases, along with mastering the overall testing process, consider exploring the Complete Guide to Software Testing & Automation by GeeksforGeeks . This course provides comprehensive insights into every aspect of software testing, from writing effective test cases to automating the testing process, helping you deliver high-quality software with confidence.

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:

  • Before development: Test cases could be written before the actual coding as that would help to identify the requirement of the product/software and carry out the test later when the product/software gets developed.
  • After development: Test cases are also written directly after coming up with a product/software or after developing the feature but before the launching of a product/software as needed to test the working of that particular feature.
  • During development: Test cases are sometimes written during the development time, parallelly. so whenever a part of the module/software gets developed it gets tested as well.

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:

  • To check whether the software meets customer expectations: Test cases help to check if a particular module/software is meeting the specified requirement or not.
  • To check software consistency with conditions: Test cases determine if a particular module/software works with a given set of conditions.
  • Narrow down software updates: Test cases help to narrow down the software needs and required updates.
  • Better test coverage: Test cases help to make sure that all possible scenarios are covered and documented.
  • For consistency in test execution: Test cases help to maintain consistency in test execution. A well-documented test case helps the tester to just have a look at the test case and start testing the application.
  • Helpful during maintenance: Test cases are detailed which makes them helpful during the maintenance phase.

Test Case Template

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

  • The Test case template contains the header section which has a set of parameters that provide information about the test case such as the tester’s name, test case description, Prerequisite, etc.
  • The body section contains the actual test case content, such as test ID, test steps, test input, expected result, etc.

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

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:

  • Testpad: Testpad is a simple tool that makes test case management easier. The software’s main motto says that it aims to find a bug that matters. A few features of Testpad include manual testing , reports of the test cases and software, dragging and dropping to make testing easier, inviting guest testers by email, building custom templates, and much more.
  • TestCaseLab: TestCaseLab is easily manageable for the test cases and could swiftly integrate them with bug trackers. The features of TestCaseLab include Custom test cases, Test Runs, Integrations of test cases, Test Plans, tags and priority for test cases, search by name of test cases, description, tags, etc.
  • TestRail: TestRail is another platform that aims to make test case management easier, it streamlines the software testing processes and along with more visibility into QA. The basic features of TestRail include management for test cases, plans, and runs, more test coverage, real-time insights into the QA progress, etc.
  • TestLodge: TestLodge is a test case management tool that helps the entire team manage their requirements, test plans, test cases, and test runs all in one single place and with no user limit. The basic features of TestLodge include Test Plans, Test Runs, a Dashboard, a Test Suite, and many more.

Formal and Informal Test Case

  • Formal Test Cases: Formal test cases are test cases that follow the basic test case format. It contains the test case parameters such as conditions, ID, Module name, etc. Formal Test cases have set input data and expected results, they are performed as per the given order of steps.
  • Informal Test Cases: Informal test cases are test cases that don’t follow the basic test case format. In these, as the tests are performed the test cases are written in real-time then pre-writing them, and the input and expected results are not predefined as well.

Types of Test Cases

  • Functionality Test Case: The functionality test case is to determine if the interface of the software works smoothly with the rest of the system and its users or not. Black box testing is used while checking for this test case, as we check everything externally and not internally for this test case.
  • Unit Test Case: In unit test case is where the individual part or a single unit of the software is tested. Here each unit/ individual part is tested, and we create a different test case for each unit.
  • User Interface Test Case: The UI test or user interface test is when every component of the UI that the user would come in contact with is tested. It is to test if the UI components requirement made by the user are fulfilled or not.
  • Integration Test Case: Integration testing is when all the units of the software are combined and then they are tested. It is to check that each component and its units work together without any issues.
  • Performance Test Case: The performance test case helps to determine response time as well as the overall effectiveness of the system/software. It’s to see if the application will handle real-world expectations.
  • Database Test Case: Also known as back-end testing or data testing checks that everything works fine concerning the database. Testing cases for tables, schema, triggers, etc. are done.
  • Security Test Case: The security test case helps to determine that the application restricts actions as well as permissions wherever necessary. Encryption and authentication are considered as main objectives of the security test case. The security test case is done to protect and safeguard the data of the software.
  • Usability Test Case: Also known as a user experience test case, it checks how user-friendly or easy to approach a software would be. Usability test cases are designed by the User experience team and performed by the testing team.
  • User Acceptance Test Case: The user acceptance case is prepared by the testing team but the user/client does the testing and review if they work in the real-world environment.

What is a QA test case?

A QA (Quality Assurance) test case is a document that specifies a set of conditions or variables under which a tester will determine whether a system, software application, or one of its features is working as expected. A well-written test case helps ensure that the software behaves as intended and meets the specified requirements. It provides us Consistency, Traceability and efficiency of System.

Benefits of writing high-quality test cases

Writing high-quality test cases offers numerous benefits that contribute to the effectiveness and efficiency of the software testing process. Some benefits are listed below:

  • Improved Test Coverage
  • Enhanced Communication
  • Consistency and Repeatability
  • Efficient Defect Identification
  • Improved Test Automation
  • Increased Confidence in Software Quality

Example test cases for a login page

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.

Related Posts:

Conclusion

Writing effective test cases is a fundamental part of the software testing process. It ensures that the software is tested thoroughly, and any defects are identified and resolved early in the development cycle. Effective test cases are clear, concise, and comprehensive, covering all possible scenarios to ensure the software’s functionality, performance, and reliability. By following a structured approach to writing test cases, testers can improve the quality of the software, reduce the risk of defects, and ensure that the software meets the requirements and expectations of the stakeholders.

FAQs

Why are test cases important?

Test cases are important because they provide a systematic way to test the software, ensure all functionalities are working as expected, help identify defects, and verify that the software meets the specified requirements.

What is the difference between a test case and a test scenario?

A test case is a detailed document that includes specific inputs, execution conditions, and expected results for a particular test. A test scenario, on the other hand, is a high-level description of what to test, typically focusing on a specific functionality or feature of the software.

What tools are commonly used for writing and managing test cases?

Common tools for writing and managing test cases include TestRail , JIRA , Zephyr, HP ALM, and Microsoft Test Manager, among others.

How do we ensure test cases cover all requirements?

To ensure test cases cover all requirements, we use a requirements traceability matrix (RTM) . This helps map test cases to specific requirements, ensuring that all requirements are tested and validated.

What are the key components of a test case?

The key components of a test case include the test case ID, test description, prerequisites, test steps, test data, expected results, actual results, and post-conditions.



Previous Article
Next Article

Similar Reads

Software Testing - Testing Retail Point of Sale(POS) Systems with Test Cases Example
POS testing refers to testing the POS application to create a successful working POS application for market use. A Point of Sale (POS) system is an automated computer used for transactions that help retail businesses, hotels, and restaurants to carry out transactions easily. What is Retail Point of Sale (POS) Testing?POS is a complex system with a
14 min read
Software Testing - Business Intelligence (BI) Testing with Sample Test Cases
The procedure in which gathering, cleaning, integrating, analyzing, and sharing data is done to determine actional experiences that drive business development is known as Business Intelligence (BI). Business Intelligence Testing checks the organizing information, ETL process, BI reports and guarantees the execution is right. BI Testing guarantees i
8 min read
Software Testing - Insurance Domain Application Testing with Sample Test Cases
Insurance Domain Application Testing is a software testing process to test the insurance application to check if the designed insurance application meets the required customer's expectations by ensuring the quality, performance, and durability requirements of the application. The following topics of insurance domain application testing will be disc
9 min read
Software Testing - Testing Telecom Domain with Sample Test Cases
Testing the telecom domain is a process of testing the telecom applications. The Telecom domain is a vast area to test. It involves testing a lot of hardware components, back-end components, and front-end components. The various products in this domain are BSS, OSS, NMS, Billing System, etc. In the telecom domain, testing is performed to ensure tha
15+ min read
HealthCare Domain Testing with Sample Test Cases - Software Testing
HealthCare Domain Testing is the process of testing software applications that are related to the healthcare industry. This can include anything from electronic health records (EHR) to hospital administration systems. There are a variety of standards and regulations that must be met for the software to be used in the healthcare industry, so it is i
15+ min read
How to Write Email Validation Test Cases?
Email validation is a critical part of any web application. It ensures that users are entering valid email addresses, which can be used for communication and authentication. Writing email validation test cases can be tricky, as there are a lot of different things to consider. Email validation test cases are an important part of any email testing st
10 min read
REST API Testing and Manual Test Cases
REST is a set of architectural styles that acts as an interface between physically separate components across the internet. In simple language, one can say that this allows the requesting system to access web resources by using a uniform and predefined set of rules. It is built on a client-server paradigm, with stateless and suitable communication.
11 min read
Test Cases For API Testing
API testing mainly focuses on understanding what APIs are and why testing them is crucial for Software application development. This section sets the stage for the rest of the document by outlining the importance of API testing ensuring robust and reliable software In this article we explain Test Cases For API Testing with related examples. Table o
6 min read
Software Testing - Web Application Testing Checklist with Test Scenarios
Web testing or web application testing ensures that your website functions as you or your clients expect as per requirements gathered during the project's initial stages. It is a comprehensive scope that touches multiple disciplines, including usability, functionality, compatibility, security, performance, and data storage and retrieval. What is We
15+ min read
Unit Testing, Integration Testing, Priority Testing using TestNG in Java
TestNG is an automated testing framework. In this tutorial, let us explore more about how it can be used in a software lifecycle. Unit Testing Instead of testing the whole program, testing the code at the class level, method level, etc., is called Unit Testing The code has to be split into separate classes and methods so that testing can be carried
6 min read
Split Testing or Bucket Testing or A/B Testing
Bucket testing, also known as A/B testing or Split testing, is a method of comparing two versions of a web page to see which one performs better. The goal of split testing is to improve the conversion rate of a website by testing different versions of the page and seeing which one produces the most desired outcome. There are a few different ways to
15+ min read
Selenium Testing vs QTP Testing vs Cucumber Testing
Automation testing will ensure you great results because it's beneficial to increased test coverage. Manual testing used to cover only few test cases at one time as compared to manual testing cover more than that. During automated test cases it's not all test cases will perform under the tester. Automation testing is the best option out of there. S
6 min read
JUnit - Writing Sample Test Cases for CutOffMarkCalculation Java Service
The quality of the software is very important. Though Unit tests and integration tests are done in the manual testing way, we cannot expect all kinds of scenarios to test. Automated testing is more helpful. In this article, how to write JUnit for the cutoff marks calculation based on caste and marks. Let us take a simpler service namely "CutOffMark
3 min read
JUnit - Sample Test Cases for String Java Service
Always automated testing helps to overcome various bugs. It will help in the integrity of the software as well. Here in this article, let us see how to write JUnit test cases for various String-related functions like "Isogram, Panagram, Anagram" etc., In the entire lifecycle of a software project, we may come across in writing this kind of function
5 min read
JUnit - Writing Sample Test Cases for StudentService in Java
In many parts of projects, collections play a major role. Among that ArrayList is a user-friendly collection and many times it will be required to develop software. Let us take a sample project that involves a "Student" model that contains attributes such as studentId, studentName, courseName, and GPA. Let's add a few services like adding/inserting
6 min read
Test Cases for Password and Forgot Password Functionality
A secure gateway for any platform holding the personal details of the user is very important. Therefore, it is very crucial to create a secure, non-faulty login page and testers should keep in mind all the possibilities while designing the test cases. The article focuses on discussing the test cases for password and forgot password functionality on
5 min read
Positive vs Negative vs Destructive Test Cases
A test case is a set of conditions or variables under which a tester will determine whether an application, software system or website meets specifications and performs as expected. A test case can be positive or negative, meaning that it tests for the correct functionality or missing functionality. What are Test Cases? A test case is a set of cond
8 min read
Test Cases For Registration and Login Page
A registration page is a page where users can sign up for an account and a login page is one where users can log in to an existing account. This page is usually the first page that users see when they visit a website. Test Cases for a Registration and Login Page Assuming there are the following fields in the registration and login page: Username.Pa
4 min read
How to create Selenium test cases
Selenium IDE is an open-source tool that is widely used in conducting automated web testing and browser automation. This tool is intended mainly for Web Application testers and developers to develop, edit, and run automated test cases for Web Applications. Table of Content What are Selenium test cases?Create Selenium test casesConclusionSelenium ID
6 min read
Test Cases for Banking Application
Banking is a completely critical enterprise. However, it is also quite complex because of all of the rules and policies, banking apps want to observe strict tips to ensure people are statistics safe, depending on in which the financial institution is positioned. Table of Content Why Test Banking Applications?Important Test Cases for Banking Applica
11 min read
Linking Test Cases and Requirements
Testlink is a software that is based on the web and it is used popularly for test management, it is a tool or software that can be used for QA testing or quality assurance testing. Linking test cases and requirements in any testing software can be a challenging task but in the case of Testlink, it allows us to quickly link the test cases with the r
4 min read
How to Manage Dependency between Test Cases?
Test case dependencies can significantly impact the effectiveness and reliability of your software testing process. As applications grow more complex, managing these dependencies becomes crucial for maintaining a robust QA strategy. This article explores key techniques and best practices for handling dependencies in test automation, ensuring your t
8 min read
How can a particular group of test cases get executed in TestNG?
In TestNG, executing a particular group of test cases is made easy with the group's feature, which allows you to categorize and organize your tests. By assigning test methods to specific groups and configuring TestNG’s XML file, you can selectively run only the relevant test cases, such as sanity, regression, or integration tests. This approach ena
3 min read
Software Testing - REST Client Testing Using Restito Tool
REST (Representational State Transfer) is a current method of allowing two software systems to communicate. REST Client is one of these systems, whereas REST Server is another. It's a design technique that uses a stateless communication protocol like HTTP. It uses XML, YAML, and other machine-readable forms to organize and arrange data. However, JS
5 min read
Software Testing - Mainframe Testing
Mainframe testing is used to evaluate software, applications, and services built on Mainframe Systems. The major goal of mainframe testing is to ensure the application or service's dependability, performance, and excellence through verification and validation methodologies, and to determine if it is ready to launch or not. Because CICS screens are
15+ min read
Software Testing - Mock Testing
Mock testing is the procedure of testing the code with non-interference of the dependencies and different variables like network problems and traffic fluctuations making it isolated from others. The dependent objects are replaced by mock objects which simulate the behavior of real objects and exhibit authentic characteristics. The motto of mock tes
9 min read
Software Testing - Cookie Testing
Cookie testing is the type of software testing that checks the cookie created in the web browser. A cookie is a small piece of information that is used to track where the user navigated throughout the pages of the website. The following topics of cookie testing will be discussed here: What are Cookies?Where cookies are stored?Why do we Need Cookie
5 min read
Confirmation Testing in Software Testing
This article describes Confirmation testing, one of the software testing techniques that is used to assure the quality of the software and covers the concepts of Confirmation testing that help testers in confirming that the software is bug-free by retesting the software till all bugs are fixed. Confirmation testing is a sub-part of change-based tes
8 min read
Software Testing - SOA Testing
SOA Testing is the process of evaluating a certain software where one can check web processes for functionality and make sure different components can communicate effectively throughout. Before diving deep into the testing model directly we need to understand SOA Architecture. What is SOA? Service Oriented Architecture (SOA) is an architectural str
13 min read
Software Testing - Back-to-Back Testing
Back-to-back testing is a method of comparing the performance of two or more systems or components by running them simultaneously and comparing their output. The goal of back-to-back testing is to determine if there is a significant difference in the performance of the systems or components being tested and identify any issues or defects that may e
9 min read