I'm writing a few UI automation test scripts using C#, NUnit and Selenium WebDriver. I would like to know if it's possible to restore the database at the end of each test (like via the TearDown method) and if so how I could achieve this.
I tried following this and this but they didn't seem to work. I'm guessing this is because I'm not executing any database related operation from the test script itself?
You can use TransactionScope
using (TransactionScope scope = new TransactionScope())
{
//your code goes here
}
Keep in mind, that auto_increment
counter values will not roll back.
I would recommend creating Fakes at your DAL layer so that you are always using the same data for each run and you won't have to worry about having a live connection to a database. I wrote a bit about the general idea here http://blog.dmbcllc.com/automated-web-application-functional-testing/ if you need more detail.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.