As an End-to-end Automation Tester I have always assumed that Given, When, Then statements (incorporated in the Gherkin Language when using Cucumber) should only ever appear in the order of 1. Given, 2. When, 3. Then.
i.e. A test should not follow, for example, Given, When, Then, When, Then. And instead should follow Given, When, Then only.
The reason for this assumption was along the lines of a single test only testing one area of the application.
However, I noticed on some gherkin examples on the web, that they use the following ordering sometimes: Given, When, Then, When, Then.
Does anyone know if this moving back to Whens after writing a Then is acceptable best practice? I appreciate the test will still work, just wondering if this is good or bad practice.
Although scenarios can be written in that way, it is not best practice. I for one, have made that mistake and it can cause problems in reports and maintenance.
One reason would be that When
declares an action and Then
verifies the result of that action. Having When - Then twice goes against the individual behavior of a scenario.
Can also get confusing for someone who reads the scenario :)
Here's a little post regarding this