docs/articles/nunit-analyzers/NUnit1027.md
| Topic | Value |
|---|---|
| Id | NUnit1027 |
| Severity | Error |
| Enabled | True |
| Category | Structure |
| Code | TestMethodUsageAnalyzer |
The test method has parameters, but no arguments are supplied by attributes.
To prevent tests that will fail at runtime due to improper construction.
[Test]
public void SampleTest(int numberValue)
{
Assert.That(numberValue, Is.EqualTo(1));
}
In the test case above, the declares that it expects one integer parameter, but no argument is supplied by the attributes. This will lead to a runtime failure.
Ensure that the correct number of arguments - and of the correct type - is supplied to test methods that expect parameters.
One possible fix to this problem would be to supply the argument using a TestCase:
[TestCase(1)]
public void SampleTest(int numberValue)
{
Assert.That(numberValue, Is.EqualTo(1));
}
Another approach could be to supply the argument using an attribute on the argument - like Range
[Test]
public void SampleTest([Range(1, 10)] int numberValue)
{
Assert.That(numberValue, Is.EqualTo(1));
}
Configure the severity per project, for more info see MSDN.
# NUnit1027: The test method has parameters, but no arguments are supplied by attributes
dotnet_diagnostic.NUnit1027.severity = chosenSeverity
where chosenSeverity can be one of none, silent, suggestion, warning, or error.
#pragma warning disable NUnit1027 // The test method has parameters, but no arguments are supplied by attributes
Code violating the rule here
#pragma warning restore NUnit1027 // The test method has parameters, but no arguments are supplied by attributes
Or put this at the top of the file to disable all instances.
#pragma warning disable NUnit1027 // The test method has parameters, but no arguments are supplied by attributes
[SuppressMessage][System.Diagnostics.CodeAnalysis.SuppressMessage("Structure",
"NUnit1027:The test method has parameters, but no arguments are supplied by attributes",
Justification = "Reason...")]