Back to Xunit

xUnit9012

site/xunit.analyzers/rules/xUnit9012.md

latest1.0 KB
Original Source

Cause

A violation of this rule occurs when [MemberData] points at an ambiguous member.

Reason for rule

The source generator must determine unambiguously which member a [MemberData] is referring to. When the named member is overloaded, it cannot determine this.

How to fix violations

To fix a violation of this rule, either remove the additional overloads or given them a different name.

Examples

Violates

csharp
using Xunit;

public class xUnit9012
{
    public static TheoryData<int> DataSource() => DataSource(1);
    public static TheoryData<int> DataSource(int multiplier) => [42 * multiplier];

    [Theory]
    [MemberData(nameof(DataSource))]
    [MemberData(nameof(DataSource), 4)]
    public void TestMethod(int _)
    { }
}

Does not violate

csharp
using Xunit;

public class xUnit9012
{
    public static TheoryData<int> DataSource(int multiplier = 1) => [42 * multiplier];

    [Theory]
    [MemberData(nameof(DataSource))]
    [MemberData(nameof(DataSource), 4)]
    public void TestMethod(int _)
    { }
}