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

Rule S2699 - Fix FP: NUnit test method using [Test(ExpectedResult=)] raises rule violation #5702

Closed
rjgotten opened this issue Jun 3, 2022 · 7 comments
Assignees
Labels
Area: C# C# rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.
Milestone

Comments

@rjgotten
Copy link

rjgotten commented Jun 3, 2022

Description

S2699 is raised for NUnit tests which use the ExpectedResult property on a TestAttribute to specify the expected result value, rather than specify an assertion in the method body.

Repro steps

[Test(ExpectedResult = 1)]
public int Sample_ReturnsExpected()
{
  return 1;
}

Expected behavior

S2699 is not raised.

Actual behavior

S2699 is raised.

Known workarounds

Avoid this particular pattern and use an assertion in the method body; or suppress the rule.

Related information

  • C#/VB.NET Plugins version: Whatever ships with Sonarlint 6.5.0.48666
  • Visual Studio version: 17.2.3
  • MSBuild / dotnet version: dotnet SDK 6.0.300
  • SonarScanner for .NET version (if used): N/A
  • Operating System: Win10
@Corniel
Copy link
Contributor

Corniel commented Jun 6, 2022

I can confirm this issue. Easy to reproduce, easy to fix.

@costin-zaharia-sonarsource costin-zaharia-sonarsource added Type: False Positive Rule IS triggered when it shouldn't be. Area: C# C# rules related issues. labels Jun 7, 2022
@costin-zaharia-sonarsource
Copy link
Member

Thanks, @rjgotten, for reporting the issue, and @Corniel, for providing the fix!

@Corniel
Copy link
Contributor

Corniel commented Jun 8, 2022

@costin-zaharia-sonarsource This issue can be closed?!

@costin-zaharia-sonarsource costin-zaharia-sonarsource changed the title S2699 FP: NUnit test method using [Test(ExpectedResult=)] raises rule violation Rule S2699 - Fix FP: NUnit test method using [Test(ExpectedResult=)] raises rule violation Jun 8, 2022
@rklec
Copy link

rklec commented Jul 28, 2022

Is this fix already released? I still get that error in the same case with v6.6.0.49766 in Visual Studio.

@Corniel
Copy link
Contributor

Corniel commented Jul 28, 2022

@rklec Yes it has.

@rklec
Copy link

rklec commented Jul 29, 2022

Okay, great! So which version contains the fix then? As I said, I could still reproduce it in v6.6.0.49766.

@costin-zaharia-sonarsource costin-zaharia-sonarsource added this to the 8.41 milestone Aug 2, 2022
@costin-zaharia-sonarsource
Copy link
Member

costin-zaharia-sonarsource commented Aug 2, 2022

This was fixed by @Corniel in the 8.41.0.50478 version of the analyzer. This was not yet embedded in the sonar lint. You can follow this ticket to see the progress: SonarSource/sonarlint-visualstudio#3097

Edit: the first ticket is now redundant as we have released 8.42 and soon we will release 8.43. You can follow this one for now: SonarSource/sonarlint-visualstudio#3107

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: C# C# rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.
Projects
None yet
Development

No branches or pull requests

4 participants