Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated rule MiKo_3122 to report tests having more than 3 parameters (instead of 2 parameters) #1142

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions MiKo.Analyzer.Shared/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions MiKo.Analyzer.Shared/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -4375,13 +4375,13 @@ This ensures precision in your tests and maintains clear expectations.</value>
<value>Tests should test concrete implementations and no interfaces</value>
</data>
<data name="MiKo_3122_Description" xml:space="preserve">
<value>Test methods with more than 2 parameters are often combined tests and can be hard to read. To improve readability, split these tests into separate ones. This makes them easier to understand and maintain.</value>
<value>Test methods with more than 3 parameters are often combined tests and can be hard to read. To improve readability, split these tests into separate ones. This makes them easier to understand and maintain.</value>
</data>
<data name="MiKo_3122_MessageFormat" xml:space="preserve">
<value>Split into multiple tests so that you do not need more than 2 parameters</value>
<value>Split into multiple tests so that you do not need more than 3 parameters</value>
</data>
<data name="MiKo_3122_Title" xml:space="preserve">
<value>Test methods should not use more than 2 parameters</value>
<value>Test methods should not use more than 3 parameters</value>
</data>
<data name="MiKo_3201_CodeFixTitle" xml:space="preserve">
<value>Invert if to simplify</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public MiKo_3122_TestMethodsDoNotHaveMultipleParametersAnalyzer() : base(Id)

protected override IEnumerable<Diagnostic> Analyze(IMethodSymbol symbol, Compilation compilation)
{
if (symbol.Parameters.Length > 2)
if (symbol.Parameters.Length > 3)
{
var syntax = symbol.GetSyntax<MethodDeclarationSyntax>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void SomeTest([Values(1)] int a, [Values(2)] int b) { }
");

[Test]
public void An_issue_is_reported_for_test_method_with_3_parameters() => An_issue_is_reported_for(@"
public void No_issue_is_reported_for_test_method_with_3_parameters() => No_issue_is_reported_for(@"
using System;

using NUnit.Framework;
Expand All @@ -89,6 +89,23 @@ public class TestMe
public void SomeTest([Values(1)] int a, [Values(2)] int b, [Values(3)] int c) { }
}
}
");

[Test]
public void An_issue_is_reported_for_test_method_with_4_parameters() => An_issue_is_reported_for(@"
using System;

using NUnit.Framework;

namespace Bla
{
[TestFixture]
public class TestMe
{
[Test]
public void SomeTest([Values(1)] int a, [Values(2)] int b, [Values(3)] int c, [Values(4)] int d) { }
}
}
");

[Test]
Expand Down Expand Up @@ -126,7 +143,7 @@ public void SomeTest(int a, int b) { }
");

[Test]
public void An_issue_is_reported_for_test_case_method_with_3_parameters() => An_issue_is_reported_for(@"
public void No_issue_is_reported_for_test_case_method_with_3_parameters() => No_issue_is_reported_for(@"
using System;

using NUnit.Framework;
Expand All @@ -140,6 +157,23 @@ public class TestMe
public void SomeTest(int a, int b, int c) { }
}
}
");

[Test]
public void An_issue_is_reported_for_test_case_method_with_4_parameters() => An_issue_is_reported_for(@"
using System;

using NUnit.Framework;

namespace Bla
{
[TestFixture]
public class TestMe
{
[TestCase(1, 2, 3, 4)]
public void SomeTest(int a, int b, int c, int d) { }
}
}
");

protected override string GetDiagnosticId() => MiKo_3122_TestMethodsDoNotHaveMultipleParametersAnalyzer.Id;
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ The following tables lists all the 471 rules that are currently provided by the
|MiKo_3119|Test methods should not simply return completed task|&#x2713;|&#x2713;|
|MiKo_3120|Moq mocks should use values instead of 'It.Is&lt;&gt;(...)' condition matcher to verify exact values|&#x2713;|&#x2713;|
|MiKo_3121|Tests should test concrete implementations and no interfaces|&#x2713;|\-|
|MiKo_3122|Test methods should not use more than 2 parameters|&#x2713;|\-|
|MiKo_3122|Test methods should not use more than 3 parameters|&#x2713;|\-|
|MiKo_3201|If statements can be inverted in short methods|&#x2713;|&#x2713;|
|MiKo_3202|Use positive conditions when returning in all paths|&#x2713;|&#x2713;|
|MiKo_3203|If-continue statements can be inverted when followed by single line|&#x2713;|&#x2713;|
Expand Down