I'm trying to create a new set of tests for testing a legacy web site that I'm working on. The site uses a database at the back end. I'm planning on using SpecFlow and Selenium, however I'm a bit stumped on what the best way to deal with cleaning up data is.
Currently I have a database backup with a set of sample data which I restore before each test run. This however is cumbersome so I would like to only do this for critical test runs before a release and leave the continuous integration runs working on the same database in between.
Currently I have a large number of tests that go something like this:
Secenario: Test Item Creation
Given I am logged in
When I create an item with a unique name
Then an item exists with the unique name
The when step uses a GUID to ensure the name is unique and the then step has access to this via a module variable to check that it exists.
Like I said however I have a lot of tests similar to this and I'm running them multiple times on the same database so the test system is getting stuffed full of items which is slowing down searches and the like.
My question is what is the best way to deal with this? Should I create another step in the test that deletes the item again like this:
Secenario: Test Item Creation
Given I am logged in
When I create an item with a unique name
Then an item exists with the unique name
Then delete the item with the unique name
Or should my test framework somehow be able to deal with this? If so what do people do? Given SpecFlow step's global nature I'd imagine that getting the teardown steps in the correct order if multiple items with parent-child relationships could become problematic.
ScenarioContext.Current
(which can't be used in parallel tests in specflow 2.0), but this is basically the right approach I feel. – Bartko