Using Specflow, I'm writing a suite of scenarios that model monthly payrolls, validating the calculated payments for each month and finally the yearend figures.
The result of each month is cumulative, so each subsequent scenario is dependent on the previous month’s additions and deductions. The payment calculations are written to a database via a third party tool, so creating and destroying test data between scenarios is expensive.
From my experience with testing, I know it's not always possible to ensure the execution sequence of the tests. I can control the sequence of execution with some scenario naming conventions, but can't guarantee that a remote test runner is going to run tests in alphabetical order.
Options I've considered:
- Run the entire year through a single scenario including lots of given, when, then assertions. This results in a single huge scenario that is difficult to read.
- Create a concatenation "Given" for each scenario. "Given: All payments to month X have been made". This creates lots of database traffic as each scenario will need to create and destroy test data.
Is there a better way to store state between scenarios and ensure scenarios are executed in the desired sequence?