简体   繁体   English

NUnit并行运行测试类别

[英]NUnit Running test categories in parallel

I have tests in different classes (Page Object pattern), that may interfere with each other when run together in parallel (they are *not* unit tests). 我有不同类的测试(页面对象模式),当并行运行时,它们可能会相互干扰(它们不是*单元测试)。 For example, there are classes: AddCustomerFormTests and EditCustomerFormTests , that test adding customers and changing customer info, respectively. 例如,有以下类: AddCustomerFormTestsEditCustomerFormTests ,分别测试添加客户和更改客户信息。 The most logical (and readable) solution seems to be to assign the fixtures to different categories and avoid running tests from the same category together, however I can't find a way to do it. 最合乎逻辑(且可读性最高)的解决方案似乎是将固定装置分配给不同的类别,并避免同时运行同一类别的测试,但是我找不到解决方法。

Basically, I'm looking for an equivalent of [Parallelizable(ParallelScope.Fixtures)] that works with categories rather than classes. 基本上,我正在寻找与类别而非类一起使用的[Parallelizable(ParallelScope.Fixtures)]等效项。 I don't want to merge classes together cause that would break Page Object pattern, as well as SRP. 我不想将类合并在一起,因为这会破坏Page Object模式以及SRP。

Interesting question! 有趣的问题! I'm afraid I don't think this is currently possible - without making modifications to the NUnit framework. 恐怕我不认为当前不可能-不对NUnit框架进行修改。 (Although don't take my word for it, others might be able to think of something!) (尽管我不相信我的话,但其他人可能会想到一些东西!)

If you were to consider making changes to the NUnit framework, I would look at implementing a new IWorkItemDispatcher to parallelise work based on categories. 如果考虑在更改NUnit的框架,我想看看实施新的IWorkItemDispatcher到parallelise基于类的工作。 You can then just select the correct dispatcher when initialising the TestExecutionContext. 然后,您可以在初始化TestExecutionContext时选择正确的调度程序。 (eg https://github.com/nunit/nunit/blob/ad943eb94fe280e661fc6c690043fe8eb0a11e40/src/NUnitFramework/framework/Api/NUnitTestAssemblyRunner.cs#L352-L358 ) (例如https://github.com/nunit/nunit/blob/ad943eb94fe280e661fc6c690043fe8eb0a11e40/src/NUnitFramework/framework/Api/NUnitTestAssemblyRunner.cs#L352-L358

An alternative way around the problem - have you considered using partial classes to group your tests, and then parallelising fixtures? 解决问题的另一种方法-您是否考虑过使用部分类对测试进行分组,然后并行处理夹具? I think that would work...you'd probably want to test this out first! 我认为这行得通...您可能要先进行测试!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM