6

I'm using mink/behat to test my website. I need certain features be executed before others. Is there a way to specify an order of execution?

For example: There are 3 features: Administration, Login, Buy I need to execute them in this order: Login, Administration, Buy

Thank you!

Bernd Strehl
  • 2,852
  • 4
  • 24
  • 43

2 Answers2

9

Behat executes files in an alphabetic order. You could prefix them with a number to force the order.

However...

Scenarios are meant to be independent and the execution order shouldn't matter.

Jakub Zalas
  • 35,761
  • 9
  • 93
  • 125
  • 8
    How would you then test very common use case of website that has to register user in order to use the same user in later tests? I know I can put user in fixtures, but that also shouldn't be a point. Also registering him in beginning of every feature is overkill. – slob Dec 09 '15 at 15:33
  • @slob that's a new question, so you should ideally post it as a new question. However, you can handle that with a beforeSuite function in your context or by having a mock user created as some other pre-testing step. There are more answers I'd give if you posted a question ;) – greggles Mar 29 '19 at 20:34
  • It "shouldn't" matter does not mean it "could" matter - and you will only find out if the case is that you do have dependencies unless you have good isolation of tests - or you regularly run in random order. Preferably both. – Barry Feb 16 '23 at 14:24
0

behat now allows you to specify an order from the existing Orderer implementations:

vendor/bin/behat --order=[random|reverse|null]

so for randon:

vendor/bin/behat --order=random

I believe you could also write your own. If you wish to control the order in terms of batches, e.g. set x scenarios need to run before set y this could be achieved by just tags and running the two separate suites in sequence.

Barry
  • 3,303
  • 7
  • 23
  • 42