How to disable a blur script

I am trying to create a new test suite to test the old website I'm working on. The site uses a database on the back. I plan to use SpecFlow and Selenium, however I am a little puzzled that the best way to handle data cleaning is this.

I currently have a database backup with a set of sampled data that I restore before each run. This, however, is cumbersome, so I would like to do it only for critical tests before release and leave continuous integration runs working in the same database between them.

I currently 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 

When a GUID is used in a step to guarantee the uniqueness of a name, then this step has access to it with a module variable to check if it exists.

As I said, I have many tests like this, and I run them several times in the same database, so the test system is filled with many objects that slow down the search, etc.

My question is the best way to handle this? Should I create another step in the test that will delete the element again as follows:

 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 handle this? If so, what are people doing? Given the global nature of the SpecFlow step, I would suggest that getting the separation steps in the correct order if multiple elements with parent-child relationships can become problematic.

+7
database specflow teardown scenarios
source share
1 answer

A good test should not have any dependencies, so creating test steps and then disrupting test data is a good idea.

One approach you can take is to keep a unique name generated with:

 When I create an item with a unique name 

in a ScenarioContext object, for example.

 ScenarioContext.Current["testItem"] = "testItemName"; 

This will allow you to keep this value throughout the script.

Then you could create a SpecFlow hook associated with a specific tag to demolish this data when the script exits, for example. The script will be (note the tag):

 @deleteTestItem Secenario: Test Item Creation Given I am logged in When I create an item with a unique name Then an item has exists with the unique name 

And the code to clear:

 [AfterScenario("deleteTestItem")] public void DeleteTestItem() { var testItemName = ScenarioContext.Current["testItemName"]; // Use testItemName to clean-up your database } 

This code will only run for scripts that have this tag. Please note: if all of your tests included creating a test item, you could omit the tag and just use the AfterScenario hook.

Alternatively, you can save all test item names in FeatureContext, and then remove these items in the AfterFeature hook. This will result in fewer database queries (i.e. you will not call the database for cleaning after each script).

I prefer the ScenarioContext approach, because I feel that if a script creates data, then this script should be responsible for cleaning up after itself.

+6
source share

All Articles