Why we are using variables in test cases?
In case your salary is correlated with the number of created test cases or executed test steps please don’t read further. But if you want to know a bit more about variables in test cases and why I use them, read more.
Variables are an easy and important part of each test case. Imagine that you have a test objective to check that you can log in to the system using different user roles. Let’s assume for now that each role uses a similar login form. Of course you can prepare a nice number of similar-looking test cases but that’s only a waste of resources. Each test case should have been written in a way that corresponds to his test objective. Checking that the user can log in will be our main goal. But also we want to make this scenario as much reusable as possible.
Example test case steps (first part is step description, while second expected step result):
- Enter login name – Field name is populated with data
- Populate password field – Password is not blank
- Click on Login button – Button redirects to main page
- Check that user is logged as “role_name” – User “role_name” is logged
In that above example, we have only one variable called “role_name”. In two different test configurations, we can use that variable and assign to her two different values. In our case “Admin” and “User”.
While test execution this variable will be called two times, giving different values each time. So for two test cases, the 4th step will look like this:
- Check that user is logged as “Admin” – User “Admin” is logged
- Check that user is logged as “User” – User “User” is logged
Why we need to use variables in our test cases?
It’s faster to write one test case than multiple doing similar things. Also, it’s easier to maintain one version than multiple scenarios. Using a few variables in one test case gives more path covered in the execution phase, without any additional resources.