Skip to content

xUnit1026 false positive with C# 12 collection literals #2789

Closed
@martincostello

Description

@martincostello

Using C# 12 collection literals with .NET 8 can cause xUnit1026 false positives.

For example:

public class FalsePositive
{
    [Theory]
    [InlineData("hello")]
    public void XUnit1026_False_Positive(string greeting)
    {
        string[] values = [greeting, "world"];
        string actual = string.Join(' ', values);
        Assert.Equal("hello world", actual);
    }
}

Produces this warning:

Theory method 'XUnit1026_False_Positive' on test class 'FalsePositive' does not use parameter 'greeting'. Use the parameter, or remove the parameter and associated data.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Analyzershttps://github.com/xunit/xunit.analyzersFeatureA request for a new featurehelp wantedA community-provided PR would be welcomed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions