Skip to main content

A quick guide to writing better test cases

This topic has been touched many times over on the internet; I'll leave out the advise of keeping simple, your test cases and the language of your test cases. Without going into methodologies and techniques used in testing, I'd like to outline a few principles of test case writing that you should bear in mind the next time you're writing test cases.

1. Design scenarios

Firstly, don't think of writing test cases.. :) Or anything related to test cases.
For the particular application / unit under test (AUT), take time to think through and identify possibilities of:
  • Inputs - All possible inputs that can be given to the AUT. Your inputs can be data or a certain action to be performed, like clicking a button
  • Outputs - All possible outcomes / behaviours of the AUT in response to the input 
  • Trigger points - Conditions that when activated, cause the AUT to perform certain action(s)
  • Alternate flows - When testing workflows, always ensure you identify flows other than the easy path / normal flow
  • Error conditions - Conditions that cause a defined error to occur / be displayed
Once you have this wealth of information with you, arrange them in an order that makes sense to you. Do this and you'll have a whole new view of the various kinds of scenarios and cases to test the unit.
You could try mixing and matching to develop various combinations of scenarios. This can become overwhelming. In such a case, I would recommend that you use the Orthogonal Arrays or some form of pairwise combinations to select only those combinations that provide the most coverage.

The difficult part's done. :)

2. Identify and define dependencies and preconditions 

Failure to identify and document these during test planning will eat into your test execution time causing you to re-execute cases properly. If dependent on data from other teams, or on outage timings, make sure you document these for awareness.

3. Don't let a test case test more than 1 desired behaviour 

Using one test case to test multiple system behaviours is a good way of landing in trouble. Not only will you find it difficult in tracing the test case back to its requirements, you will also find it difficult to place where exactly a defect lies.

4. Write test cases that are independent of each other & executable in any order

One test case should not be dependent on any other test case as far as possible. What this does is reduce the number of test cases that could potentially be blocked in case of a defect. And in turn, you'll be better positioned to wrap up testing within a tight time frame.

I am a bit under the weather as I write this post. And hence have not elaborated too finely on the points.

Now that you are aware of the finer points of test case writing, be sure you don't commit these 3 common mistakes while testing.

Is your test phase dragging along? Identify and optimize these activities that slow you down.

Let me know what you think through the comments.

Till the next post,
Savio Saldanha

Please note that my team is available to undertake software testing assignments. You may reach out to bureauofquality@gmail.com with your needs.

Comments

Popular posts from this blog

3 Common mistakes that testing teams should avoid

A friend and I were recently talking about the kind of common yet critical mistakes that are made quite unknowingly during the test phase of the SDLC. Some of the points mentioned below are the kind of processes mandated by companies for ages! It is not uncommon to see that test managers, along with the test leadership within companies making such blunders. And if you see such practices being followed at your company, let them know that they should be ridding themselves of these common mistakes. 1. Test cases are not traced back to the requirements One of essential artifacts of the testing phase is the Requirement Trace-ability Matrix. What this matrix does is help you link your requirements to your test cases. As a result, you would be aware of the coverage your test cases provide to your requirements. Not having an RTM puts you and your team at the risk of coming up with an incomplete coverage of the requirements  and the possibility of leaking defects. Her...

Attention! These 3 Activities are Slowing Down Your Testing!

These are activities you perform almost daily. You're tired of the monotonous work involved and yet its hard to realize that these are the activities that you must optimize in order to speed up your testing process. You would probably have these at the back of your mind.. Let me help you bring them to the fore! 1. You derive your test cases from a requirement document: We're all faced with this situation each time some piece of code needs to be tested. We look for the requirements, and frame our test scenarios and test cases. Have you ever thought what exactly are you doing by writing test cases? You're simply rewording the requirements! Something simple for example: Requirement = The login page will allow system access to the user by authenticating his/her username and password. The user will be allowed to enter the username and password through text boxes of not more than 20 characters (this does not mean the data type char). Test Case#1 = Verify the presence of ...