有序 Selenium 单元测试 n [英] Ordered Selenium unit tests n

查看:28
本文介绍了有序 Selenium 单元测试 n的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小问题,我创建了一些 Selenium 测试.问题是我无法订购我创建的测试用例.我知道不应该订购单元测试,但这是我在我的情况下需要的.我必须遵循以下步骤:首先登录,创建一个新客户,更改有关客户的一些详细信息,最后注销.

I have a small problem, I have created some Selenium tests. The problem is I can't order the testcases I have created. I know unit testing should not be ordered but this is what I need in my situation. I have to follow these steps: login first, create a new customer, change some details about the customer and finally log out.

由于在 NUnit 中没有订购单元测试的选项,因此我无法执行此操作.

Since there is no option to order unit tests in NUnit I can't execute this.

我已经尝试了另一种选择,在 Visual Studio 中创建一个单元测试项目,因为 Visual Studio 2012 能够创建一个有序的单元测试.但这不起作用,因为我在运行 ASP.NET 项目时无法运行单元测试.另一个解决方案文件也不是一个好的选择,因为我想在通过 Selenium 测试提交后验证我的数据.

I already tried another option, to create a unittest project in Visual Studio, because Visual Studio 2012 has the ability to create a ordered unit test. But this is not working because I can't run a unit test while I am running my ASP.NET project. Another solution file is also not a good option because I want to verify my data after it has been submitted by a Selenium test.

你们中有人有其他解决方案来解决我的问题吗?

Does someone of you have another solution to solve my problem?

推荐答案

如果您想以特定的顺序(并通过它的声音,作为单个会话)测试所有这些步骤,那么实际上它更像是一个 验收测试您正在谈论;在这种情况下,编写更复杂的测试方法并在每个步骤后断言条件 不是罪.

If you want to test all of those steps in a specific order (and by the sounds of it, as a single session) then really it's more like an acceptance test you are talking about; and in that case it's not a sin to write more complex test methods and Assert your conditions after each step.

如果您想真正隔离地测试每个步骤(纯单元测试),那么每个单元测试必须能够自行运行,而无需参考任何其他测试;但是当您测试实际的网站 UI 本身时,这并不是您真正的选择.

If you want to test each step in true isolation (a pure unit test) then each unit test must be capable of running by itself without any reference to any other tests; but when you're testing the actual site UI itself this isn't really an option for you.

当然,如果您真的想让每个测试都以某种方式设置每个依赖项而不参考任何其他操作(例如,在最后一个测试中,您需要伪造登录令牌,您的数据层将不得不假装您添加了一个新客户等.很多工作都是为了可疑的利益......)

Of course if you really you want to have every single test somehow setup every single dependency without reference to any other actions (e.g in the last test you would need to fake the login token, your data layer will have to pretend that you added a new customer, etc. A lot of work for dubious benefit...)

我这么说是基于这样一个假设,即您已经为服务器端控制器、层、模型等编写了单元测试,您在运行时没有参考浏览器中运行的实际站点,因此确信您网站的各个后端部分都在做他们应该做的事情

在您的情况下,我建议您进行更多的混合集成/验收测试

In your case I'd recommend more of a hybrid integration/acceptance test

void Login(IWebDriver driver)
{
   //use driver to open browser, navigate to login page, type user/password into box and press enter

}

void CreateNewCustomer(IWebDriver driver)
{
  Login(driver);
  //and then use driver to click "Create Customer" link, etc, etc

}

void EditNewlyCreatedCustomer(IWebDriver driver)
{
  Login(driver);
  CreateNewCustomer(driver);
  //do your selenium stuff..

}

and then your test methods:
[Test]
void Login_DoesWhatIExpect()
{
  var driver = new InternetExplorerDriver("your Login URL here");   
  Login(driver);
  Assert(Something);
}
[Test]
void CreateNewCustomer_WorksProperly()
{
   var driver = new InternetExplorerDriver("your Login URL here");   
   CreateNewCustomer(driver);
   Assert(Something);
}
[Test]
void EditNewlyCreatedCustomer_DoesntExplodeTheServer()
{
   var driver = new InternetExplorerDriver("your Login URL here");   
   EditNewlyCreatedCustomer(driver);
   Assert(Something);
}

这样,具体测试的顺序无关紧要;当然,如果 Login 测试失败,那么 CreateNewCustomerEditNewlyCreatedCustomer 测试也将失败,但这在这种情况下实际上无关紧要,因为您正在测试整个线程"操作

In this way the order of the specific tests do not matter; certainly if the Login test fails then the CreateNewCustomer and EditNewlyCreatedCustomer tests will also fail but that's actually irrelevant in this case as you are testing an entire "thread" of operation

这篇关于有序 Selenium 单元测试 n的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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