简体   繁体   English

如何从命令行并行运行 NUnit 测试?

[英]How to run NUnit tests in parallel from command line?

My NUnit test is written in C# and it is built using .net core 3.1.我的 NUnit 测试是用 C# 编写的,它是使用 .net 核心 3.1 构建的。 I am trying to run the tests inside it in parallel.我正在尝试并行运行其中的测试。 I know that I can set the Parallelizable attribute at the fixture level like this [Parallelizable(ParallelScope.Fixtures)].我知道我可以像这样 [Parallelizable(ParallelScope.Fixtures)] 在夹具级别设置 Parallelizable 属性。 But, that is not what I am looking for.但是,这不是我要找的。 I want to run the tests from command line using "dotnet test".我想使用“dotnet test”从命令行运行测试。

So, I was just checking if there is any way to run like this所以,我只是在检查是否有任何方法可以这样运行

   dotnet test --parallel FullyQualifiedName~NUnitNamespace.UnitTest1

   dotnet test --parallel C:\NUnitTestDemo\bin\Debug\netcoreapp3.1\testproject.dll

Anything in the command-line has to be passed to NUnit.命令行中的任何内容都必须传递给 NUnit。 NUnit allows restricting parallelism using arguments passed in but it doesn't allow the runner to force running in parallel. NUnit 允许使用传入的 arguments 来限制并行性,但它不允许运行器强制并行运行。

If you think about it, that is logical.如果你仔细想想,那是合乎逻辑的。

The attribute is [Parallelizable] , where "IZABLE" means "capable".该属性是[Parallelizable] ,其中“IZABLE”表示“有能力”。 The test author uses the attribute to tell NUnit that a particular test is capable of running in parallel.测试作者使用该属性告诉 NUnit 特定测试能够并行运行。 Without that assurance, NUnit cannot know whether the test is sufficiently independent of others to run without errors or false positives.如果没有这种保证,NUnit 无法知道测试是否足够独立于其他测试以运行而不会出现错误或误报。

So in the test you can tell NUnit whether it's able to run all or some of the tests in parallel.所以在测试中你可以告诉 NUnit 它是否能够并行运行所有或部分测试。 In theory, NUnit might run them in parallel or not but in fact if it's possible it runs the tests in parallel up to the specified limit of parallel test workers.理论上,NUnit 可能会并行运行它们,但实际上,如果可能的话,它会并行运行测试,直到指定的并行测试工作者限制。 That limit can be specified either with an attribute at the assembly level or by the runner.该限制可以在程序集级别使用属性指定,也可以由运行程序指定。

If running with the NUnit console runner, you set the limit using the --workers option.如果使用 NUnit 控制台运行程序运行,则使用 --workers 选项设置限制。 When you use dotnet test, you need to specify it in a .runsettings file, using the NumberOfTestworkers setting.使用 dotnet test 时,需要使用NumberOfTestworkers设置在.runsettings文件中指定它。 To completely suppress parallelism, use a value of 0. A value of 1 suppresses most parallelism but still allows tests to run at the same time if one is in the STA and one in the MTA.要完全抑制并行性,请使用值 0。值 1 会抑制大多数并行性,但如果一个在 STA 中,一个在 MTA 中,仍允许测试同时运行。

See https://github.com/nunit/docs/wiki/Tips-And-Tricks for a list of settings you can use.有关可以使用的设置列表,请参阅https://github.com/nunit/docs/wiki/Tips-And-Tricks

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

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