2
Scenario1 
When a new user  clicks on sign up page
And provides login ID 
Then user is signed up and can view profile page.
Scenario2 
When user  clicks on the edit profile page
And updates his address
Then updated profile should be visible to user

The scenarios are written in a feature file in the same sequence. When writing the cucumber file for the same, I am creating a user in the scenario 1. And in scenario 2 , the same user is being updated. In a way, scenario2 is dependent on 1 as it is updating the same user that was created in scenario1.

My question is should the scenarios be created so that they are dependent on other scenarios. Or they should be independent of each other execution.. in which case I should create a new user in scenario2 and then perform and update on it and assert it.

javaGroup456
  • 313
  • 1
  • 6
  • 21
  • [Background](https://relishapp.com/cucumber/cucumber/docs/gherkin/background) might be what you are looking for. – kaskelotti Dec 14 '19 at 09:17
  • In this particular example .. yes. But is such dependency encouraged in any case ? Even when I know that the sequence of execution of 2 scenarios would be as expected. – javaGroup456 Dec 14 '19 at 09:22
  • It is not recommended, see my answer below (copied from the Cucumber FAQ) – Marit Dec 24 '19 at 11:22

1 Answers1

5

Cucumber explicitly recommends you do not make your Scenarios depend on each other. From the FAQ's:

"Each scenario should be independent; you should be able to run them in any order or in parallel without one scenario interfering with another.

Each scenario should test exactly one thing so that when it fails, it fails for a clear reason. This means you wouldn’t reuse one scenario inside another scenario.

If your scenarios use the same or similar steps, or perform similar actions on your system, you can extract helper methods to do those things."

(Sidenote: From personal experience, I can tell you that tests that depend on each other / the state of the system, will very quickly become very hard to maintain. I'd highly recommend you to make your tests independent!)

Marit
  • 2,399
  • 18
  • 27