7

I'm trying to run multiple Specflow tests in the Test Explorer, but the challenge is I'm unable to run them in the desired order.

ex - I have 3 scenarios in my feature files:

  • Login positive
  • Login negative
  • registration positive

Currently, they run in random order. I want them to always run in the above order. How can I configure my feature files to make it possible?

Rhythm Kalra
  • 79
  • 1
  • 1
  • 3
  • why do you want them to run in order – L_Church Apr 20 '18 at 13:48
  • 2
    Agree with the above comment. Best practice with unit tests and even integration / web-ui tests is that a test should be self-contained and be capable of running regardless of external factors such as test ordering. In short - there should be no inter-test dependencies. – Baaleos Apr 20 '18 at 14:31
  • 1
    The scenario is such that the complete registration process happens in 4 steps i.e 4 different screens and thus I wanted to have each step as a different test primarily because they are different screens. – Rhythm Kalra Apr 30 '18 at 13:41

2 Answers2

7

For NUnit: Tests inside a scenario run in alphabetical order, so if you want to run them in specific order just rename scenarios like

Scenario: 1 Login positive
Scenario: 2 Login negative
Scenario: 3 Registration positive

For other frameworks look here: https://www.ontestautomation.com/running-your-tests-in-a-specific-order/

applekate
  • 304
  • 3
  • 8
3

I also think it is so annoying if the tests order in the feature files different than the text explorer. So here is my solution to that.

Scenario: 01) Create test data
    Given ...
    When ...
    Then ...
    
Scenario: 02) Modify data
    Given ...
    When ...
    Then ...

Scenario: 03) Remove modified data
    Given ...
    When ...
    Then ...

Source

Bashir Momen
  • 1,461
  • 19
  • 17