site/xunit.analyzers/rules/xUnit1019.md
This rule is triggered when your [MemberData] attribute points to a member does not have a valid return type (IEnumerable<object[]> or something compatible with it, like TheoryData<>). For v3 tests, this also includes support for IAsyncEnumerable<> as well as supporting ITheoryDataRow in addition to object[] to represent a single row of data.
[MemberData] attributes which do not point to valid data sources will fail at runtime.
To fix a violation of this rule, update the data member to have an appropriate return type.
[!NOTE] Using the types
object[]orITheoryRowDatawill trigger xUnit1042 because they are not strongly typed. It is strongly suggested that you choose to useTheoryData<>for v2/v3, orIEnumerable<TheoryDataRow<>>/IAsyncEnumerable<TheoryDataRow<>>for v3, as those provide compiler-level type safety and additional code analysis is possible to ensure the types of the test method parameters match the generic types of your theory data.</p>
using System.Collections.Generic;
using Xunit;
public class xUnit1019
{
public static IEnumerable<object> TestData;
[Theory]
[MemberData(nameof(TestData))]
public void TestMethod(string greeting, int age) { }
}
For v2 and v3
using System.Collections.Generic;
using Xunit;
public class xUnit1019
{
public static IEnumerable<object[]> TestData;
[Theory]
[MemberData(nameof(TestData))]
public void TestMethod(string greeting, int age) { }
}
For v3 only
using System.Collections.Generic;
using Xunit;
public class xUnit1019
{
public static IEnumerable<ITheoryDataRow> TestData;
[Theory]
[MemberData(nameof(TestData))]
public void TestMethod(string greeting, int age) { }
}
using System.Collections.Generic;
using Xunit;
public class xUnit1019
{
public static IAsyncEnumerable<object[]> TestData;
[Theory]
[MemberData(nameof(TestData))]
public void TestMethod(string greeting, int age) { }
}
using System.Collections.Generic;
using Xunit;
public class xUnit1019
{
public static IAsyncEnumerable<ITheoryDataRow> TestData;
[Theory]
[MemberData(nameof(TestData))]
public void TestMethod(string greeting, int age) { }
}