从UI到DB - 使用Selenium和NUnit集成测试 [英] Integration testing using Selenium and NUnit - From UI to DB

查看:130
本文介绍了从UI到DB - 使用Selenium和NUnit集成测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有尝试使用Selenium和NUnit创建集成测试的一些问题。

I am having some problems while trying to create integration tests with Selenium and NUnit.

我想使用Selenium RC在NUnit测试开我的ASP.NET Web应用程序,并想测试真正做到在DB所有的东西,真正的用户会怎么做。自然硒做了之后的事情,我已经断言,数据库包含从UI的数据新行(等),这将是很好,如果数据库可以得到回滚。

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.

所以,这里的设置,我有(某种形式的伪code的):

So, here's the setup i have (in some sort of pseudocode):

TestMethod()
{
    Using(new TransActionScope)
    {
        Selenium.StartSelenium()
        Selenium.SelectAndClickAndDoStuffInUI()
        AssertSomething()
    }
}

现在,SelectAndClickAndDoStuffInUI法点击周围的UI,从而触发了我们的专有DA-框架。我们的框架写的所有东西到数据库,并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.

所以,一切都很好,对不对?不,可惜不是。在这个例子中的TransactionScope上面应该不会被提交(不txScope.Complete() - 调用有),因此所有的内部事务应该得到回滚过,对吧?那么,他们不这样做,一切硒确实通过UI被提交到数据库中。

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:

为什么的TransactionScope不会得到在我的例子所示的情况下回滚?

我会很乐意提供有关情况和设置的其它信息!

I will gladly provide additional information about the situation and setup!

推荐答案

您使用的是用户界面的ASP应用程序。这意味着你的测试无法回滚所做的更改。

You are using a UI to an asp app. That means your test is not able to rollback the changes you made.

本次交易范围可以在自己的过程中才能正常工作。是怎样的事务管理器能够撤消webinterface内点击?它可以在任何地方。硒是刚刚远程控制的浏览器。

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.

您应该创建真实的单元测试与模拟对象,而不是在所有访问数据库。它有点难以用普通的ASP页面,但你不能看看asp.MVC找到一个可能的解决这个问题。

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.

这篇关于从UI到DB - 使用Selenium和NUnit集成测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆