简体   繁体   中英

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. 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)]. But, that is not what I am looking for. I want to run the tests from command line using "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 allows restricting parallelism using arguments passed in but it doesn't allow the runner to force running in parallel.

If you think about it, that is logical.

The attribute is [Parallelizable] , where "IZABLE" means "capable". The test author uses the attribute to tell NUnit that a particular test is capable of running in parallel. Without that assurance, NUnit cannot know whether the test is sufficiently independent of others to run without errors or false positives.

So in the test you can tell NUnit whether it's able to run all or some of the tests in parallel. 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. 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. When you use dotnet test, you need to specify it in a .runsettings file, using the NumberOfTestworkers setting. 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.

See https://github.com/nunit/docs/wiki/Tips-And-Tricks for a list of settings you can use.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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