You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm seeing S2187 reported when using test fixtures that have test methods that derive from AutoData (an attribute defined in Autofixture.NUnit3) instead of the built-in Test, TestMethod, etc attributes from NUnit.
Such attributes implement the ITestBuilder interface from NUnit, and these tests are correctly detected and run by visual studio.
Repro steps
Create a test fixture in a correctly-configured Test project that uses the NUnit, AutoFixture, and Autofixture.NUnit3 packages, with the following code:
S2187 is reported on the FalsePositiveS2187TestFixture class.
Known workarounds
Suppress the issue.
Put a superfluous Test attribute on at least one method in the affected class.
Related information
Visual Studio 17.0.5
SonarLint for VS 2022 version 6.1.0.45943
I don't know what version of the C# plugin on SonarQube, but we have SonarQube 9.4.0.
As far as I understand it, this could be fixed by additionally blessing methods with attributes that implement the ITestBuilder interface, rather than the specific ones provided by NUnit.
That seems like it'd be fairly straightforward-- I'd be happy to investigate doing so myself.
The text was updated successfully, but these errors were encountered:
dammejed
changed the title
S2187 reported when using test attributes deriving from ITestMethodBuilder in NUnit tests.
S2187 reported when using test attributes deriving from ITestBuilder in NUnit tests.
Apr 14, 2022
pavel-mikula-sonarsource
changed the title
S2187 reported when using test attributes deriving from ITestBuilder in NUnit tests.
Fix S2187 FP: Support test attributes deriving from ITestBuilder in NUnit
Apr 19, 2022
Description
I'm seeing S2187 reported when using test fixtures that have test methods that derive from
AutoData
(an attribute defined in Autofixture.NUnit3) instead of the built-inTest
,TestMethod
, etc attributes from NUnit.Such attributes implement the
ITestBuilder
interface from NUnit, and these tests are correctly detected and run by visual studio.Repro steps
Create a test fixture in a correctly-configured Test project that uses the NUnit, AutoFixture, and Autofixture.NUnit3 packages, with the following code:
Expected behavior
No S2187 is raised.
Actual behavior
S2187 is reported on the
FalsePositiveS2187TestFixture
class.Known workarounds
Test
attribute on at least one method in the affected class.Related information
As far as I understand it, this could be fixed by additionally blessing methods with attributes that implement the
ITestBuilder
interface, rather than the specific ones provided by NUnit.That seems like it'd be fairly straightforward-- I'd be happy to investigate doing so myself.
The text was updated successfully, but these errors were encountered: