Using shared steps when writing test cases
Shared step definition
What is shared steps
Shares step is a single step in the test case or sequence of steps, which could be reused in any other test case
Information about how to create and use shared steps could be found on Share steps between test cases Microsoft documentation page
Using parameters in the share steps
Add parameters to a test case
Please refer to the oficial microsoft documentation Add parameters to a test case
Share parameters between test cases
Please refer to the Shaer parameters between test cases microsoft documentation page
Using shared steps in the API testing
There’re some examples below, how we can cover Create an Agent endpoint using shared steps
To properly cover this enpoind we need to use serveral types of the test cases:
positive
negative
permission check
Obviously, we’ll have a suite of test cases and in every test case we need to repeat the step where we send the request, but request body could be different in every test case or in some test cases.
Let’s create the shared step to describe the request exectuion - https://redboxdev.visualstudio.com/Nubis/_workitems/edit/30461
In shared step we can describe the request, expected results and add any additional required information (screenshots, etc…)
Now let’s try to reuse this shared step for negative test cases, for example, send “Create an agent“ reqeust with invalid email
It becomes dificult to write readable test case using shared steps, as it’s not clear where to put invalid parameter and seems like we need to create another shared steps but with different request body.
In the eample above we duplicated the request body in several test cases what is, obviously, bad practice.
One of possible solution is to change the name of shared step in a way to make it more common:
Given create an agent request
Now we can use it in a following way to make the test case more readable
But what if just want to mention the shared step, for example, in the preconditions:
If we reffer to the shared step in this way, need to add realted shared step link to the current test case manually:
One more example, but in this case shared step name is “Create an agent“
We need to agree on the shared steps usage in different types of test cases and different situations