How to write a Test Case?
First of all, what is a test case?
A test case is a documented artifact consisting of certain actions or sequence of events for testing the software product against a specific requirement(s). It generally, involves the set of test data pre-specified conditions & environment, expected result in order to simulate a test scenario so as to verify and validate a particular requirement.
What are the components of a test case?
A particular test case format, usually, comprises of following variables:
- Test Case ID
- Functionality or feature to be tested
- Test Scenario
- Test Data
- Test Environment details
- Steps for the execution
- Expected Outcome
- Actual Result
- Comments or attachments(if any)
Now, how to write a test case?
Our motive should be "How to write effective test cases". As verifying and validating, the requirements or functionality is driven by the test case(s), writing an effective test case should be the utmost priority to cover all the essential features and aspects of the software product under the test in order to achieve a quality product.
The steps in a direction to write an effective test case may be seen as under:
- First step involves identifying the purpose behind the testing along with its scope which may include analysis of the user or business requirements.
- Defining and detailing the activities, to be carried out, during the testing process based on the test scenarios & functional requirements, of the software product, which works as a manual to write a test case.
- Further, a test framework based on the requirements is to be designed to ensure the coverage of functionality, compatibility, fault tolerance, UI Interface and other performance aspects of the software product.
- Know about the modules of the software product and became familiar with each of the modules in order to consider and weigh their importance while writing the test cases.
- Now, with all the gathered data and information, test cases may be structured, detailed and written based on the mapping of requirements to test scenarios such that each test scenario may have one or more than test cases.
- Thereafter, assigning the test priority to each of the prepared test cases based on the importance of functionality, requirements and specifications.
Further, a tester may make the usage of the test case management tools, to bring more effectiveness in the test cases along with some other useful purposes, such as
- Documenting the test cases.
- Automating the process of defect tracking.
- For traceability.
- Maintaining the test cases.
Some Do's & Don'ts for writing the test case
- Test case should be simple, precise and concise which may be, easily, understood in first reading without the help of a tester/professional who has written it.
- User perspective may be taken into consideration in writing the test cases so as to meet the customer's requirement.
- Try to make use of the traceability matrix to ensure that no functionality or requirement as mentioned in the SRS or BRS is left, unseen or unvisited.
- Assign ID to each of the test cases so as to manage and track the requirements and bugs.
- Try to write independent, reusable & repeatable test cases to generate the same output irrespective of a person who is executing it.
- Do not write unnecessary or redundant test execution steps.
- Do not consider or assume any sort of requirements on your own without consulting the SRS or BRS.
- Do not write repetitive test cases.
- Do not forget to review the test cases by the development team.