How to write a test case in software development (with tips)

By Indeed Editorial Team

Published 3 January 2022

The Indeed Editorial Team comprises a diverse and talented team of writers, researchers and subject matter experts equipped with Indeed's data and insights to deliver useful tips to help guide your career journey.

It's important to properly test a piece of software to ensure it functions and performs to the standards you expect it to. Test cases are a valuable tool for examining different aspects of a piece of software to ensure they function correctly or to identify and eliminate potential issues. Understanding how to write a test case can be valuable knowledge if you're ever involved in software development or testing. In this article, we explain what a test case is, how to write a test case and a few tips you may wish to consider when writing one.

How to write a test case

Consider following these steps if you wish to create a test case for your software:

1. Assign a test ID

It's generally good practice to assign each test case a unique ID to represent them. This can help a company ensure clarity and organisation of test cases being carried out. Using test IDs can be a good way to help find, review and study test cases and accurately document or report them. To be most effective when cataloguing test cases and results, it's best to be consistent with your identification system. In this way, relevant stakeholders can quickly find test cases of interest and review different aspects of your testing during any discussions on software development and functionality.

Related: How to become a software development engineer in test: a guide

2. Create the test case description

Your test description looks to detail what feature, function or unit of the software you are testing or what aspect you are verifying. The description covers in basic terms what the software programme does in response to certain input or conditions. The descriptions themselves don't have any coding value or executable data but instead are there to provide relevant context to the tester carrying out the test case. An example of a test case description for a login page may read 'check username and password fields when the user clicks the login button', for example.

3. Identify assumptions and pre-conditions

This encompasses any conditions the user has to meet before executing the test case. We use the two terms largely interchangeably, but there are subtle differences between assumptions and pre-conditions. To highlight the difference with an example, when testing a spell-checker a pre-condition may be having a dictionary of words available to provide possible matches. The assumption may be that the user is capable of independently selecting the correct match. Examples of pre-conditions testers may encounter include using a specific browser or internet extension or activating an ad-blocker.

4. Add test data

To begin testing and verifying a programme, start adding data related to the variables in the test case. So in the example of testing a login function, the data is username and password information. If carrying out multiple test cases, identifying data may be the longest step of the software verification process. Taking the time to properly identify data, though, can help understand what the programme identifies and documents as a pass or fail of the established conditions being tested.

5. List the steps to execute

Write out easily repeatable steps for the end-user to follow to carry out the test case. These steps allow testers to activate the scenarios that test the functionality or software aspect the test case is examining. Generally, we design these steps so employees who don't necessarily have a lot of coding experience can follow them and carry out test cases. Continuing the example of testing login functionality, the test case steps may be something like:

  • open browser

  • open company intranet login portal

  • enter username

  • enter password

  • click 'enter' on the keyboard or the 'login' button on the screen

6. Identify your expected results

When designing the test case, identify the expected outcome of end-users following the steps you wish them to execute. This provides a benchmark for the test case so you can determine whether the software is functioning as you expect and wish it to. Following the example steps listed above, the expected result is a successful login to the company intranet for the user.

7. Record your actual results and postconditions

For each test, record and track the actual results of following the test case steps. You can then compare these against your expected results to get a picture of the functionality of the software. Comparing the actual result against the expected result lets you determine the status of the test case. The postconditions are what happens as a result of executing the steps in the test case. With the login example, the postcondition is navigating the user to the company intranet page.

8. Determine the pass/fail status of the test

This is essentially the result of your test case. It's a simple way for stakeholders to identify functionalities and different aspects of the software that are or aren't working as expected. We determine the status by comparing the actual result against the expected result. If the results are the same, the test case has a 'pass' status. If the actual result doesn't match the expected results, then the test case is a 'fail'.

What is a test case?

A test case is where programmers use a series of coding functions to test the functionality of their software. It tests conditions or actions in the software to see if they produce the desired result. They're typically intended to test basic tasks or variables, such as whether password rules are working. This approach allows software testers to be more flexible in the way they test features and code. Through carrying out multiple tests cases, a software engineer can determine whether the overall programme is functioning properly.

Test cases can use manual or automated testing or may make use of specific case management tools. Within companies, employees from different departments may manually test departmental programmes. Employees may run test cases on intranet software, databases or other applications to ensure they're functional and optimised to meet the specific needs of the company.

Related: What are the different testing types that analysts use?

Tips for writing a test case

When writing a test case for a piece of software, you may wish to consider the following tips:

Use simple language

It's generally best when designing a test case to use simple language. It may be that you are testing an application for a specific department in your company, such as an HR database. It may be best to have end-users in HR test functionality, but they may not have a particularly technical understanding of software development. Accessible, simple language allows them to carry out the test cases. Such language also means other stakeholders can easily review aspects of the test, or replicate the test cases themselves.

Related: 6 essential software engineer skills

Keep end-user goals in mind

We typically design many software products to provide some sort of function to end-users. These end-users may be company employees, customers or organisations. Test cases work best when they are as convenient to the end-user as possible, as does software in general. Consider keeping the interface experience of the end-user in mind when designing your test case. Possibly include prompts or other additional instructions in your test case to make it simple and convenient to navigate. If a software product is simple to operate, this may translate into improved client satisfaction with the product.

Review specifications during testing

Testing provides the opportunity to conduct quality assurance during the development stages before you make the product available to customers. Consider reviewing the product specifications throughout the testing process to ensure your product is matching up with expectations. Test cases may identify conditions or functionalities that are lacking when compared to what the client requested. Keep referring back to the specifications and carefully run an array of test cases to ensure the finished product fully meets client expectations.

Consider external testing

After conducting your initial test cases, you may wish to consider external testing and verification before delivering the finished product to your client. Having departments outside of your team or even outside of your organisation independently test your software can help verify the results of your test cases and give you an extra level of confidence in its functionality. It may also identify problems you hadn't anticipated and aid with regression fixing. For example, one aspect may have functioned perfectly during test cases, but external verification shows that a system patch on the external tester's operating system now affects functionality.

Be aware of testing techniques

There are several different testing techniques you can employ when carrying out a test case. These may help save time during the verification process. Such techniques include:

  • Boundary value analysis: This approach tests boundaries for a different range of values. For instance, you may wish to define a certain field to always have a number only rather than testing that field for multiple kinds of input.

  • Equivalence partition: This technique divides fields into parts and allows you to test the same types of values. So, you may wish to divide your fields into two groups and use one test for every field that has numeric value input and another test for fields that use text.

  • Error guessing: This is a predictive approach that can help save time during testing. It lets developers assume one type of error may lead to other, similar errors.

Explore more articles