docs/articles/nunit-analyzers/NUnit1023.md
| Topic | Value |
|---|---|
| Id | NUnit1023 |
| Severity | Error |
| Enabled | True |
| Category | Structure |
| Code | ValueSourceUsageAnalyzer |
The target method expects parameters which cannot be supplied by the ValueSource.
To prevent tests that will fail at runtime due to improper construction.
public class MyTestClass
{
[Test]
public void StringTest([ValueSource(nameof(Strings))] string input)
{
Assert.That(input, Is.Not.Null);
}
static IEnumerable<string> Strings(string first, string second)
{
yield return first;
yield return second;
}
}
In the sample above, the method Strings expects two arguments, but the ValueSource cannot supply arguments.
Change Strings so that it does not expect any arguments:
public class MyTestClass
{
[Test]
public void StringTest([ValueSource(nameof(Strings))] string input)
{
Assert.That(input, Is.Not.Null);
}
static IEnumerable<string> Strings()
{
yield return "first";
yield return "second";
}
}
Configure the severity per project, for more info see MSDN.
# NUnit1023: The target method expects parameters which cannot be supplied by the ValueSource
dotnet_diagnostic.NUnit1023.severity = chosenSeverity
where chosenSeverity can be one of none, silent, suggestion, warning, or error.
#pragma warning disable NUnit1023 // The target method expects parameters which cannot be supplied by the ValueSource
Code violating the rule here
#pragma warning restore NUnit1023 // The target method expects parameters which cannot be supplied by the ValueSource
Or put this at the top of the file to disable all instances.
#pragma warning disable NUnit1023 // The target method expects parameters which cannot be supplied by the ValueSource
[SuppressMessage][System.Diagnostics.CodeAnalysis.SuppressMessage("Structure",
"NUnit1023:The target method expects parameters which cannot be supplied by the ValueSource",
Justification = "Reason...")]