-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #502 from manfred-brands/issue442_TestCaseSourcePa…
…rameterCheck Issue442 test case source parameter check
- Loading branch information
Showing
10 changed files
with
407 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# NUnit1029 | ||
|
||
## The number of parameters provided by the TestCaseSource does not match the number of parameters in the Test method | ||
|
||
| Topic | Value | ||
| :-- | :-- | ||
| Id | NUnit1029 | ||
| Severity | Error | ||
| Enabled | True | ||
| Category | Structure | ||
| Code | [TestCaseSourceUsesStringAnalyzer](https://github.com/nunit/nunit.analyzers/blob/master/src/nunit.analyzers/TestCaseSourceUsage/TestCaseSourceUsesStringAnalyzer.cs) | ||
|
||
## Description | ||
|
||
The number of parameters provided by the TestCaseSource must match the number of parameters in the Test method. | ||
|
||
Note that the current implementation only works for single parameters. | ||
|
||
## Motivation | ||
|
||
A `TestCaseSourceAttribute` is used to pass parameters to a test method, but the test method does not expect any or more parameters than supplied. | ||
|
||
```charp | ||
private static readonly IEnumerable<string> NUnitNameSpaces = new[] { ".NUnit", ".NUnitExtensions" }; | ||
[TestCaseSource(nameof(NUnitNameSpaces))] | ||
public void IsNUnit() | ||
{ | ||
} | ||
``` | ||
|
||
## How to fix violations | ||
|
||
Match the number of parameters between the test data and the test method. | ||
|
||
<!-- start generated config severity --> | ||
## Configure severity | ||
|
||
### Via ruleset file | ||
|
||
Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). | ||
|
||
### Via .editorconfig file | ||
|
||
```ini | ||
# NUnit1029: The number of parameters provided by the TestCaseSource does not match the number of parameters in the Test method | ||
dotnet_diagnostic.NUnit1029.severity = chosenSeverity | ||
``` | ||
|
||
where `chosenSeverity` can be one of `none`, `silent`, `suggestion`, `warning`, or `error`. | ||
|
||
### Via #pragma directive | ||
|
||
```csharp | ||
#pragma warning disable NUnit1029 // The number of parameters provided by the TestCaseSource does not match the number of parameters in the Test method | ||
Code violating the rule here | ||
#pragma warning restore NUnit1029 // The number of parameters provided by the TestCaseSource does not match the number of parameters in the Test method | ||
``` | ||
|
||
Or put this at the top of the file to disable all instances. | ||
|
||
```csharp | ||
#pragma warning disable NUnit1029 // The number of parameters provided by the TestCaseSource does not match the number of parameters in the Test method | ||
``` | ||
|
||
### Via attribute `[SuppressMessage]` | ||
|
||
```csharp | ||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Structure", | ||
"NUnit1029:The number of parameters provided by the TestCaseSource does not match the number of parameters in the Test method", | ||
Justification = "Reason...")] | ||
``` | ||
<!-- end generated config severity --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# NUnit1030 | ||
|
||
## The type of parameter provided by the TestCaseSource does not match the type of the parameter in the Test method | ||
|
||
| Topic | Value | ||
| :-- | :-- | ||
| Id | NUnit1030 | ||
| Severity | Error | ||
| Enabled | True | ||
| Category | Structure | ||
| Code | [TestCaseSourceUsesStringAnalyzer](https://github.com/nunit/nunit.analyzers/blob/master/src/nunit.analyzers/TestCaseSourceUsage/TestCaseSourceUsesStringAnalyzer.cs) | ||
|
||
## Description | ||
|
||
The type of parameters provided by the TestCaseSource must match the type of parameters in the Test method. | ||
|
||
Note that the current implementation only works for single parameters. | ||
|
||
## Motivation | ||
|
||
A `TestCaseSourceAttribute` is used to pass parameters to a test method, but the test method expects a different type of parameter. | ||
|
||
```charp | ||
private static readonly IEnumerable<string> NUnitNameSpaces = new[] { ".NUnit", ".NUnitExtensions" }; | ||
[TestCaseSource(nameof(NUnitNameSpaces))] | ||
public void IsNUnit(int n) | ||
{ | ||
} | ||
``` | ||
|
||
## How to fix violations | ||
|
||
Match the type of parameters between the test data and the test method. | ||
|
||
|
||
<!-- start generated config severity --> | ||
## Configure severity | ||
|
||
### Via ruleset file | ||
|
||
Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). | ||
|
||
### Via .editorconfig file | ||
|
||
```ini | ||
# NUnit1030: The type of parameter provided by the TestCaseSource does not match the type of the parameter in the Test method | ||
dotnet_diagnostic.NUnit1030.severity = chosenSeverity | ||
``` | ||
|
||
where `chosenSeverity` can be one of `none`, `silent`, `suggestion`, `warning`, or `error`. | ||
|
||
### Via #pragma directive | ||
|
||
```csharp | ||
#pragma warning disable NUnit1030 // The type of parameter provided by the TestCaseSource does not match the type of the parameter in the Test method | ||
Code violating the rule here | ||
#pragma warning restore NUnit1030 // The type of parameter provided by the TestCaseSource does not match the type of the parameter in the Test method | ||
``` | ||
|
||
Or put this at the top of the file to disable all instances. | ||
|
||
```csharp | ||
#pragma warning disable NUnit1030 // The type of parameter provided by the TestCaseSource does not match the type of the parameter in the Test method | ||
``` | ||
|
||
### Via attribute `[SuppressMessage]` | ||
|
||
```csharp | ||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Structure", | ||
"NUnit1030:The type of parameter provided by the TestCaseSource does not match the type of the parameter in the Test method", | ||
Justification = "Reason...")] | ||
``` | ||
<!-- end generated config severity --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.