C# 如何并行运行 NUnit(Selenium Grid)测试?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/212863/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 18:21:36  来源:igfitidea点击:

How can I run NUnit(Selenium Grid) tests in parallel?

c#seleniumtestingnunitselenium-grid

提问by Benjamin Lee

My current project uses NUnit for unit tests and to drive UATs written with Selenium. Developers normally run tests using ReSharper's test runner in VS.Net 2003 and our build box kicks them off via NAnt.

我当前的项目使用 NUnit 进行单元测试并驱动使用 Selenium 编写的 UAT。开发人员通常在 VS.Net 2003 中使用 ReSharper 的测试运行器运行测试,我们的构建框通过 NAnt 启动它们。

We would like to run the UAT tests in parallel so that we can take advantage of Selenium Grid/RCs so that they will be able to run much faster.

我们希望并行运行 UAT 测试,以便我们可以利用 Selenium Grid/RCs 使它们能够运行得更快。

Does anyone have any thoughts on how this might be achieved? and/or best practices for testing Selenium tests against multiple browsers environments without writing duplicate tests automatically?

有没有人对如何实现这一目标有任何想法?和/或针对多个浏览器环境测试 Selenium 测试而不自动编写重复测试的最佳实践?

Thank you.

谢谢你。

采纳答案by Maxime Rouiller

There hasn't been a lot of work on this subject. I didn't find anything really relevent.

关于这个主题的工作并不多。我没有发现任何真正相关的东西。

However, your point is well taken. Most machines nowadays have more cores and less powerful cores compared to powerful one core cpu.

但是,您的观点很好。与强大的单核 CPU 相比,如今大多数机器拥有更多的内核和功能较弱的内核。

So I did find something on a Microsoft blog. The technology is called PUnit and is made especially for testing multi-threaded environment.

所以我确实在微软博客上找到了一些东西。该技术称为 PUnit,专门用于测试多线程环境。

It's as close as possible to what you requested that I could find :)

它尽可能接近你所要求的,我可以找到:)

You can visit it the appropriate blog post right there: http://blogs.microsoft.co.il/blogs/eyal/archive/2008/07/09/punit-parallel-unit-testing-in-making.aspx

您可以在那里访问相应的博客文章:http: //blogs.microsoft.co.il/blogs/eyal/archive/2008/07/09/punit-parallel-unit-testing-in-making.aspx

Update: Link is not valid anymore. The project on CodePlex has been removed.

更新:链接不再有效。CodePlex 上的项目已被删除。

Update2: This is on the roadmap for NUnit 2.5. Reference

更新 2:这是 NUnit 2.5 的路线图。参考

回答by Maxime Rouiller

I struggled with both these problems myself. In the end I developed a custom Nunit test runner that is capable of running multiple tests in parrallel. This combined with the Taumuon.Rakija extension for nunit allowed the tests to be dynmaically created depending on which browser you want the test to run on.

我自己也在努力解决这两个问题。最后我开发了一个自定义的 Nunit 测试运行器,它能够并行运行多个测试。这与 nunit 的 Taumuon.Rakija 扩展相结合,允许根据您希望测试运行的浏览器动态创建测试。

I'm now in a position where I can launch my test suite against as many browser types on as many operating systems as I wish in parrallel.

我现在处于这样一个位置,我可以在尽可能多的操作系统上针对尽可能多的浏览器类型以并行方式启动我的测试套件。

Unfortunately there doesn't seem to be a good solution to these problems already so you'll probably have to solve them yourself for your particular environment.

不幸的是,这些问题似乎还没有很好的解决方案,因此您可能必须针对您的特定环境自己解决这些问题。

回答by Bigwave

Igor Brejc has a blog post about running tests in parallel using MbUnit.

Igor Brejc 有一篇关于使用 MbUnit 并行运行测试的博客文章。

However he does say "Once we integrate Selenium into acceptance testing", so it looks like he was just experimenting, I can't find any other posts so I don't know if he has successfully run Selenium tests in parallel.

但是他确实说“一旦我们将 Selenium 集成到验收测试中”,所以看起来他只是在试验,我找不到任何其他帖子,所以我不知道他是否成功地并行运行了 Selenium 测试。

http://igorbrejc.net/development/continuous-integration/gallio-running-tests-in-parallel

http://igorbrejc.net/development/continuous-integration/gallio-running-tests-in-parallel

回答by Dave Bush

You can use the Task Parallel Library and the DynamicObject class to achieve parallelization of the same test on multiple browsers. See my article Running Selenium In Parallel with any .NET Unit Testing Toolfor details.

您可以使用 Task Parallel Library 和 DynamicObject 类在多个浏览器上实现同一测试的并行化。有关详细信息,请参阅我的文章使用任何 .NET 单元测试工具并行运行 Selenium

回答by Peter

NUnit version 3 will support running tests in parallel, this works good with a Selenium Grid:

NUnit 版本 3 将支持并行运行测试,这适用于 Selenium Grid:

Adding the attribute to a class: [Parallelizable(ParallelScope.Self)]will run your tests in parallel with other test classes.

将属性添加到类:[Parallelizable(ParallelScope.Self)]将与其他测试类并行运行您的测试。

? ParallelScope.None indicates that the test may not be run in parallel with other tests.

? ParallelScope.Self indicates that the test itself may be run in parallel with other tests.

? ParallelScope.Children indicates that the descendants of the test may be run in parallel with respect to one another.

? ParallelScope.Fixtures indicates that fixtures may be run in parallel with one another.

? ParallelScope.None 表示该测试不能与其他测试并行运行。

? ParallelScope.Self 表示测试本身可以与其他测试并行运行。

? ParallelScope.Children 表示测试的后代可以彼此并行运行。

? ParallelScope.Fixtures 表示夹具可以彼此并行运行。

NUnit Framework-Parallel-Test-Execution

NUnit 框架-并行-测试-执行