Table of Contents
  v2 v3   Error

xUnit9012

"MemberData member may not be overloaded"

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

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

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 _)
    { }
}