-
Notifications
You must be signed in to change notification settings - Fork 158
NUnit1009
Mikkel Nylander Bundgaard edited this page Apr 25, 2020
·
2 revisions
Topic | Value |
---|---|
Id | NUnit1009 |
Severity | Error |
Enabled | True |
Category | Structure |
Code | ParallelizableUsageAnalyzer |
One may not specify ParallelScope.Children on a non-parameterized test method.
To prevent tests that will fail at runtime due to improper construction.
[Parallelizable(ParallelScope.Children)]
[Test]
public void NUnit1009SampleTest()
{
Assert.Pass();
}
In the sample above, the Parallelizable
attribute is used with ParallelScope.Children
.
However, in a non-parameterized test, such as a [Test]
and not a [TestCase]
, there will be no children generated, and thus this type of parallelization does not make sense.
Remove the attribute:
[Test]
public void NUnit1009SampleTest()
{
Assert.Pass();
}
Or, turn the test into one that will have children generated, such as a TestCase
:
[Parallelizable(ParallelScope.Children)] // These will now run in parallel
[TestCase(1)]
[TestCase(2)]
public void NUnit1009SampleTest(int numberValue)
{
Assert.That(numberValue, Is.GreaterThan(0));
}
Configure the severity per project, for more info see MSDN.
#pragma warning disable NUnit1009 // No ParallelScope.Children on a non-parameterized test method.
Code violating the rule here
#pragma warning restore NUnit1009 // No ParallelScope.Children on a non-parameterized test method.
Or put this at the top of the file to disable all instances.
#pragma warning disable NUnit1009 // No ParallelScope.Children on a non-parameterized test method.
[System.Diagnostics.CodeAnalysis.SuppressMessage("Structure",
"NUnit1009:No ParallelScope.Children on a non-parameterized test method.",
Justification = "Reason...")]
Copyright (c) 2018 The NUnit Project - Licensed under CC BY-NC-SA 4.0