Home Guide How to write Test Cases with Examples

How to write Test Cases with Examples

Shreya Bose, Technical Content Writer at BrowserStack -

Table of Contents

What is a Test Case?

In the context of software testing, a test case refers to the sequence of actions required to verify a specific feature or functionality. Essentially, the test case details the steps, data, prerequisites, and postconditions necessary to verify a feature.

It will lay out particular variables which QAs need to compare expected and actual results to conclude if the feature is working as it should. Test case components mention input, execution, and expected output/response. Basically, it tells engineers what to do, how to do it, and what results are acceptable.

The Objective of Writing Test Cases

  • To validate specific features and functions of the software.
  • To guide testers through their day-to-day hands-on activity.
  • To record a catalog of steps undertaken, which can be revisited in the event of a bug popping up.
  • To provide a blueprint for future projects and testers so that they don’t have to start work from scratch.
  • To help detect usability issues and design gaps early on.
  • To help new testers and devs quickly pick up testing, even if they join in the middle of an ongoing project.

Standard Test Case Format

  • Test Case ID
  • Test Scenario
  • Test Steps
  • Prerequisites
  • Test Data
  • Expected/Intended Results
  • Actual Results
  • Test Status – Pass/Fail

While writing test cases, remember to include:

  • A reasonable description of the requirement
  • A description of the test process
  • Details related to test setup: version of the software under test, data points, OS, hardware, security clearance, date, time, prerequisites, etc.
  • Any related documents or attachments testers will require
  • Alternative to prerequisites, if they exist

Common Features of Test Cases

  • Likely to be revised and updated regularly. Software requirements can change, depending on changes in business priorities or customer preferences. If requirements change, test cases will have to be altered accordingly. The detection of bugs and debugging steps may also require test cases to be changed.
  • Likely to involve clustering. Test cases in a single test scenario usually have to be run in a specific sequence or in a group. In this case, particular pre-requisites of one test case will apply to other test cases in the same sequence.
  • Likely to be interdependent. Often, test cases can depend on each other. This is especially true for layered applications with multi-tier business logic.
  • Likely to be used by testers as well as developers. Test cases are helpful for developers as well as testers. For example, when devs are fixing bugs, test cases can be pretty useful to replicate said bug. In Test-Driven Development (TDD), devs create test cases to craft business logic, cover multiple test scenarios, and start writing code.

Test Case Example

Let’s build a test case example based on a specific scenario. Here is a sample case.

  • Test Case ID: #BST001
  • Test Scenario: To authenticate a successful user login on Gmail.com
  • Test Steps:
    • The user navigates to Gmail.com.
    • In the ’email’ field, the user enters a registered email address.
    • The user clicks the ‘Next’ button.
    • The user enters the registered password.
    • The user clicks ‘Sign In.’
  • Prerequisites: A registered Gmail ID with a unique username and password.
  • Browser: Chrome v 86. Device: Samsung Galaxy Tab S7.
  • Test Data: Legitimate username and password.
  • Expected/Intended Results: Once username and password are entered, the web page redirects to the user’s inbox, displaying and highlighting new emails at the top.
  • Actual Results: As Expected
  • Test Status – Pass/Fail: Pass

Best Practices for Writing Test Cases

  • Prioritize clarity and transparency. Be clear, concise, and assertive in describing what the tester needs to do and what results they should ideally get.
  • Focus on End-User requirements when writing sample test cases. Map test cases to reflect every aspect of the user journey. Use the Specifications Document and the Requirements Document to do so.
  • Avoid repetition. If multiple tests can be executed with the same test case, use the Test Case ID to refer to the required test case.
  • Keep Test Steps as minimal as possible. Ideally, keep it to 10-15 steps, if possible.
  • Focus on achieving maximum test coverage. While 100% test coverage is rarely achievable, a high percentage can be attained with the right strategies.
  • Create self-cleaning test cases. That means test cases must revert the Test Environment to a pristine, pre-test state. Tests should not leave any remnants of themselves in the environment when they are completed. This is an integral element of Configuration Management. To understand more in depth: What is Configuration Management in DevOps?
  • Shape test cases for tests that return the same results no matter who runs them. Ensure that tests are self-standing.

Once test cases have been shaped, corresponding tests must be run on real browsers, devices, and operating systems. Remember that device fragmentation is a significant concern for every developer and tester. Every website has to work seamlessly on multiple device-browser-OS combinations. With 9000+ distinct devices being used to access the internet globally, all software must be optimized for different configurations, viewports, and screen resolutions.

Try Testing on Real Device Cloud for Free

In this state, no emulator or simulator can replicate real user conditions. Software needs to be tested on real devices to work in real-world circumstances such as a low battery, incoming calls, weak network strength, and so on. If an in-house lab is not accessible, opt for a cloud-based testing option that offers real devices.

BrowserStack’s cloud Selenium grid offers 2000+ real devices and browsers for automated testing. That means users can run tests on multiple real devices and browsers by simply signing up, logging in, and selecting the required combinations. Testers can also conduct Cypress testing on 30+ real browser versions across Windows and macOS. Detect bugs before users do by testing software in real user conditions with BrowserStack.

Note: Do not release software without testing on real devices. When users visit, they will encounter bugs and errors that could have been easily avoided, and disruptive user experiences will result in the loss of users.

Creating well-structured and result-oriented test cases is fundamental to running successful tests. Additionally, they ensure comprehensive test coverage and provide a clear plan for QAs to follow. Use this article to learn the fundamentals of creating effective test cases and start executing tests designed to optimize and deliver top-of-the-line user experiences.

Tags
Fragmentation

Featured Articles

How to determine the right testing metrics

How to make your Selenium test cases run faster

How to set Proxy in Firefox using Selenium WebDriver?

BrowserStack Logo Test Instantly on 2000+ Real Devices & Browsers Contact us Get Started Free