问题
I am having some problems while trying to create integration tests with Selenium and NUnit.
I'm trying to use Selenium RC in NUnit test to drive my ASP.NET web app, and would like the tests to actually do all the stuff in DB that the real user would do. Naturally it would be nice if the database could get rolled back after Selenium has done it's thing, and i've asserted that db contains the new rows (etc) with the data from the ui.
So, here's the setup i have (in some sort of pseudocode):
TestMethod()
{
Using(new TransActionScope)
{
Selenium.StartSelenium()
Selenium.SelectAndClickAndDoStuffInUI()
AssertSomething()
}
}
Now, the SelectAndClickAndDoStuffInUI-method clicks around in UI and thus fires up our proprietary da-framework. Our framework writes all the stuff into db, and the AssertSomething-method asserts that everything is fine in db. Framework uses transactions ("required") in it's inner workings.
So everything is fine, right? No, sadly not. The TransActionScope in the example above shouldn't get committed (no txScope.Complete()-call there), and thus all the inner transactions should get rolled back too, right? Well they do not, and everything Selenium does through the UI gets committed to DB.
I've really tried to understand where this goes wrong, but so far haven't found the answer.
Thanks for reading, and (finally) here's the actual question:
Why the TransactionScope does not get rolled back in the case shown in my example?
I will gladly provide additional information about the situation and setup!
回答1:
You are using a UI to an asp app. That means your test is not able to rollback the changes you made.
The transaction scope can only work in your own process. How is the transaction manager able to undo the click inside a webinterface? It could be anywhere. Selenium is just remote controlling a browser.
You should create your "real" unit tests with mock objects, and not access the database at all. Its a little hard with a normal asp page, but you cant take a look at asp.MVC to find a possible solution to this problem.
来源:https://stackoverflow.com/questions/1458524/integration-testing-using-selenium-and-nunit-from-ui-to-db