Hi Bill, I'm going to walk you through the steps. It's a long explanation, so be patient...!
Ready? Let's go :-).
Let's first lay out the scenarios(test cases):
1 - You have a "base" feature where you create a new user with a unique phone number. Let's call it Create_New_User.feature.
In this feature file, create an annotation @Create-New-User. Place this annotation at the first line (above the "Feature:" key word).
2 - And let say you have 5 scenarios that are dependent on the condition that the new user account must exist. Place them in the same feature file called Dependency_Test_Cases.feature: For each scenario, create an annotation called @Test-Case-1, @Test-Case-2...Test-Case-5. Place the corresponding annotation just above the "Scenario:" key word.
3 - Create a feature file, and call it Delete_New_User.feature
In this feature file, create an annotation @Delete-New-User. Place this annotation at the first line (above the "Feature:" key word). In this feature file you need to cover two conditions: (1) if the user exists? Remove the user. (2) if not, do nothing. Just exist the test case.
4 - And let say you have 5 scenarios that are NOT dependent on the condition that the new user account must exist. Place them in the same feature file called Non_Dependency_Test_Cases.feature: For each scenario, create an annotation called @Test-Case-6, @Test-Case-7...Test-Case-10. Place the corresponding annotation just above the "Scenario:" key word.
What I just did was to breakdown the test cases into individual ones so that you can call them as you like. They're just like independent functions which you can combine/use them in any way that you like to.
Now let say you want to create a TestSuite that have dependency on the condition that the user must exist. You want to test the case where the execution should follow this order:
1) A new user is created
2) Test-Case-1.
Here is how you can do that. Create a Test Runner class "Create_New_User_And_Run_Test_Case_1.java". The contend of the class will look like this:
import cucumber.api.CucumberOptions;
import net.serenitybdd.cucumber.CucumberWithSerenity;
import org.junit.runner.RunWith;
@RunWith(CucumberWithSerenity.class)
@CucumberOptions(
features={"src/test/resources/features"},
tags={"@Create-New-User, @Test-Case-1"}
)
public class FutureLoginRunnerTestSuite {
}
Do the same of any test case that you want to. Another example, if you can to run the following test cases:
1 - Create a new user.
2 - Run Test-Case-1.
5 - Run Test-Case-5.
Then your Test Suite will look like this:
import cucumber.api.CucumberOptions;
import net.serenitybdd.cucumber.CucumberWithSerenity;
import org.junit.runner.RunWith;
@RunWith(CucumberWithSerenity.class)
@CucumberOptions(
features={"src/test/resources/features"},
tags={"@Create-New-User, @Test-Case-1, @Test-Case-5"}
)
public class FutureLoginRunnerTestSuite {
}
Question: So... how the execution knows what you want to run? And in what order?
Answer: Your Test runner tells the execution to follow exactly order that you stated in the "tags" option.
Now... a note of caution: This is very important note that you need to pay attention to. The way the cucumber works is a bit weird. The cucumber execution actually does NOT follow what you state in your "tags" option. It follows its now rules of execution. The execution order is based on Alpha-Numeric order of the annotation name. This order of execution has thrown me off when I first learnt of Cucumber. It took me quite a while to figure it out.
Let's take look at our example number 1 again. As expected, the execution will first execute @Create-New-User and then @Test-Case-1. Now let say you have the @Test-Case-1 changed to @ATest-Case-1, then what would happen? What would happen is that the execution order will be: @ATest-Case-1 then @Create-New-User. Now that will break your test suite.
In short, when you name your annotations, make sure follow the Alpha-Numeric orders that you want to execute them.
Now, you can create any test suites that you want and you don't have to put all test cases under the same dependency any more.
Still confused? Just ask :-).
Good luck!
J.N