-
Notifications
You must be signed in to change notification settings - Fork 160
NUnit1004
Mikkel Nylander Bundgaard edited this page Apr 25, 2020
·
2 revisions
| Topic | Value |
|---|---|
| Id | NUnit1004 |
| Severity | Error |
| Enabled | True |
| Category | Structure |
| Code | TestCaseUsageAnalyzer |
The number of arguments provided by a TestCaseAttribute must match the number of parameters of the method.
To prevent tests that will fail at runtime due to improper construction.
[TestCase("1", "2")]
public void NUnit1004SampleTest(string parameter1)
{
Assert.That(parameter1, Is.EqualTo("1"));
}In the sample above, there are two arguments provided by test case (TestCase("1", "2")), but only one parameter is being expected by the test itself ((string parameter1)).
Either make use of the additional argument:
[TestCase("1", "2")]
public void NUnit1003SampleTest(string parameter1, string parameter2)
{
Assert.That(parameter1, Is.EqualTo("1"));
Assert.That(parameter2, Is.EqualTo("2"));
}Or remove it:
[TestCase("1")]
public void NUnit1003SampleTest(string parameter1)
{
Assert.That(parameter1, Is.EqualTo("1"));
}Configure the severity per project, for more info see MSDN.
#pragma warning disable NUnit1004 // Too many arguments provided by TestCaseAttribute.
Code violating the rule here
#pragma warning restore NUnit1004 // Too many arguments provided by TestCaseAttribute.Or put this at the top of the file to disable all instances.
#pragma warning disable NUnit1004 // Too many arguments provided by TestCaseAttribute.[System.Diagnostics.CodeAnalysis.SuppressMessage("Structure",
"NUnit1004:Too many arguments provided by TestCaseAttribute.",
Justification = "Reason...")]Copyright (c) 2018 The NUnit Project - Licensed under CC BY-NC-SA 4.0