Skip to content

NET-3623 Fix S3433 FP: Allow generic type parameter in test method for MSTest #9785

Open

Description

@drieseng

Description

Currently, S3433 is reported when a data-driven test method in MSTest has a generic type parameter.
This is effectively supported by MSTest, so S3433 should not be reported.

Reproducer

Compile the following class with MSTest and S3433 enabled:

using System;
using System.Collections.Generic;

using Microsoft.VisualStudio.TestTools.UnitTesting;

[TestClass]
public sealed class SonarBug
{
    [TestMethod]
    [DynamicData(nameof(GetNameOfT_TestData))]
    public void GetNameOfT<T>(T value, string expected)
        where T : struct, Enum
    {
        var actual = Enum.GetName(value);
        Assert.AreEqual(expected, actual);
    }

    private static IEnumerable<object?[]> GetNameOfT_TestData()
    {
        yield return [DateTimeKind.Local, "Local"];
        yield return [DateTimeKind.Utc, "Utc"];
    }
}

Expected result:

S3433 is not reported. When you run the test you'll get two test results.

Actual result:

S3433 is reported.

Product and Version

SonarAnalyzer.CSharp v10.18.0.131500

Activity

  1. changed the title [-]Fix S3433 FP: Allow generic type parameter in test method for MSTest[/-] [+]NET-3623 Fix S3433 FP: Allow generic type parameter in test method for MSTest[/+] on Apr 17, 2026
  2. github-actions commented on Apr 17, 2026

    @github-actions
    Contributor

    Internal ticket NET-3623

  3. oleksandr-selehenenko-sonarsource commented on Apr 17, 2026

    @oleksandr-selehenenko-sonarsource
    Contributor

    Hello @drieseng,
    Thanks for the report and reproducer. I've confirmed the false positive with S3433 and added it to our backlog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    False PositiveRule IS triggered when it shouldn't be.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions