0

In my feature file I have 1 scenario outline with two examples that creates two teams. These teams are preconditions to two other scenarios: one deletes the empty team and one adds a user to a team. Obviously I require that the team creation runs before the other two scenarios. I named them starting with 01(for the team creation)/02(removing team)/03(adding user). Now, when I run dotnet test this executes fine. But when I use VS Test Explorer the tests are displayed like this in a tree:

 _02RemoveTeam
 _03AddUser
+_01AddTeam
|- AddTeam("team1")
|- AddTeam("team2")

As you can test cases coming from scenario outline go at the end. Question is simple: how do I prevent that? I just want my tests executed in alphabetical order.

Alternatively I was considering using Gherkin's Background keyword, but to my knowledge Background cannot be parametrized so I wouldn't be able to create two teams with different names.

1 Answer 1

1

This is the kind of problem that comes up when tests depend on one another. Fixing this means each test needs to be independent. Add steps to the "add team member" and "delete team" scenarios to create the team. You don't need to be elaborate with this. Depending on your scenario, the step can be as simple as Given a team was created where the step definition uses fake or test data for all the details necessary to create the team. No need to specify things in a scenario when that information is not relevant.

Resolving this, in my experience, means doing two things:

  • Add Given steps to each scenario to include all precursor use cases.
  • Do not specify more information in each of those steps than is necessary for the current scenario. If the name of the team really doesn't matter, then don't give the team a name.
Sign up to request clarification or add additional context in comments.

4 Comments

Test order matters, that's true. But I don't believe it is a fundamental problem :-) The fundamental problem is that Gherkin doesn't support it properly. Yes, I could write all the team creation logic in a Given step definition. But then I need to have a separate scenario that actually creates a team. Therefore I would be duplicating team creation logic: once in a scenario and once on Given step definition. Or am I missing something?
@TomaszGrobelny: I think you misunderstood the first sentence. The problem is that test order matters -- that's the problem. Test order should not matter. That will solve your problem. Tests should not depend on one another.
I clarified the first sentence.
That still doesn't address the problem I raised about code duplication. I am not willing to trade one problem for another.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.