Deleting created data from Automated Tests?
carriann last edited by
So what's the best way to go about this? Lets pretend im testing localhost, or a remote site. That either has a mysql or postgreSQL database.
I have a few automated tests that create things (X,Y,Z widgets). However deleting these would require clicking a link based on the xpath where it resides on a list of widgets to delete.
This seems....very brittle.
Is there a better way around this? Our main goal is to strengthen regression testing after pushing a new feature to a site that is sort of in "maintenance/final mode"). So resetting the database seed file is possible (This is mostly rails sites).
I would use database cleaner, but I cannot find a good tutorial on using it with capybara/poltergeist. Plus im not sure it works on remote sites (Since im not spinning up a capybara server, im hitting a remote site even if it's just localhost).
Or are tests that "add" things just not a good idea in general, or I just have to deal with using brittle tests to delete the items?
Why not just delete whole database and copy it from clear master copy?
Unless you want to test deleting those artifacts, wiping the whole database and replacing it with a clean copy seems fastest and rock-solid solution.
re @Stanislav Bashkyrtsev answer: but to create randomized test which adapt to existing data is more work (== more possibility to add a bug to your tests, adding false positive or negative), and artifact leftovers after failed test might break tests which would pass on clean data. Leaving artifact you add one more cause of failure, which is not relevant to production code.