问题
I'm using NUnit 3.8
in Visual Studio Professional 2017
.
I've got [assembly: Parallelizable(ParallelScope.Fixtures)]
designated in my AssemblyInfo.cs
file. This makes the default behavior that tests within classes cannot run in parallel with other tests within that class, but they can run in parallel with tests of other classes.
I'm wondering if it's possible to keep that default behavior but invert the logic on a class-by-class basis. I want to have tests within a specific class run in parallel with one another, but not with tests of other classes.
Take the code below. If I were to run all the tests below - I would want all of the tests in TestClassA to execute in parallel until all were done, and THEN all tests from TestClassB would execute in parallel.
[NonParallelizable]
public class TestClassA
{
[Test]
[Parallelizable(ParallelScope.Children)]
[TestCase(1, 1)]
[TestCase(2, 2)]
[TestCase(3, 3)]
[TestCase(4, 4)]
public void TestIntsA(int a, int b)
{
System.Threading.Thread.Sleep(1000);
Assert.AreEqual(a, b);
}
}
[NonParallelizable]
public class TestClassB
{
[Test]
[Parallelizable(ParallelScope.Children)]
[TestCase(1, 2)]
[TestCase(2, 3)]
[TestCase(3, 4)]
[TestCase(4, 5)]
public void TestIntsB(int a, int b)
{
System.Threading.Thread.Sleep(1000);
Assert.AreEqual(a, b);
}
}
Based on this NUnit documentation (specific excerpt below), I would think this is possible.
Non-parallel class with parallel methods:
The methods only run in parallel with one another, not with the test methods of any other classes.
However, when I've run the above code with three worker threads, the first three tests run successfully, and then no more tests are initiated. The test run hangs in limbo until I cancel the test run.
Any suggestions?
回答1:
You code sample looks correct. There's been a few bugs such as https://github.com/nunit/nunit/issues/2438 which have caused problems with test case parallelization in v3.8. The team are working on v3.8.2 at the moment, which should resolve these issues.
A number of problems have been resolved already - you may wish to try the latest build of master to see if your case has been fixed:
https://ci.appveyor.com/project/CharliePoole/nunit/build/3.9.0-dev-04489/artifacts
来源:https://stackoverflow.com/questions/46554172/way-to-run-nunit-tests-within-class-in-parallel-but-not-run-with-other-class-te