ClassData must point at a valid class
The type referenced by the [ClassData]
attribute does not implement IEnumerable<object[]>
or does not have a public parameterless constructor. For v3 projects, the class may also implement IAsyncEnumerable<object[]>
, IEnumerable<ITheoryDataRow>
, or IAsyncEnumerable<ITheoryDataRow>
.
xUnit.net will attempt to instantiate and enumerate the type specified in [ClassData]
in order to retrieve test data for the theory. In order for instantiation to succeed, there must be a public parameterless constructor. In order for enumeration to work, the type must implement IEnumerable<object[]>
.
To fix a violation of this rule, make sure that the type specified in the [ClassData]
attribute meets all of these requirements:
class
or a struct
type.IEnumerable<object[]>
.using Xunit;
class xUnit1007_TestData { }
public class xUnit1007
{
[Theory]
[ClassData(typeof(xUnit1007_TestData))]
public void TestMethod(int quantity, string productType)
{ }
}
using System.Collections;
using System.Collections.Generic;
using Xunit;
class xUnit1007_TestData : IEnumerable<object[]>
{
public IEnumerator<object[]> GetEnumerator()
{
yield return new object[] { 12, "book" };
yield return new object[] { 9, "magnifying glass" };
}
IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator();
}
public class xUnit1007
{
[Theory]
[ClassData(typeof(xUnit1007_TestData))]
public void TestMethod(int quantity, string productType)
{ }
}
using System.Collections.Generic;
using System.Threading;
using Xunit;
class xUnit1007_TestData : IAsyncEnumerable<object[]>
{
public async IAsyncEnumerator<object[]> GetAsyncEnumerator(CancellationToken cancellationToken = default)
{
yield return new object[] { 12, "book" };
yield return new object[] { 9, "magnifying glass" };
}
}
public class xUnit1007
{
[Theory]
[ClassData(typeof(xUnit1007_TestData))]
public void TestMethod(int quantity, string productType)
{ }
}
using System.Collections;
using System.Collections.Generic;
using Xunit;
class xUnit1007_TestData : IEnumerable<TheoryDataRow<int, string>>
{
public IEnumerator<TheoryDataRow<int, string>> GetEnumerator()
{
yield return new TheoryDataRow<int, string>(12, "book");
yield return new TheoryDataRow<int, string>(9, "magnifying glass");
}
IEnumerator IEnumerable.GetEnumerator() => throw new System.NotImplementedException();
}
public class xUnit1007
{
[Theory]
[ClassData(typeof(xUnit1007_TestData))]
public void TestMethod(int quantity, string productType)
{ }
}
using System.Collections.Generic;
using System.Threading;
using Xunit;
class xUnit1007_TestData : IAsyncEnumerable<TheoryDataRow<int, string>>
{
public async IAsyncEnumerator<TheoryDataRow<int, string>> GetAsyncEnumerator(CancellationToken cancellationToken = default)
{
yield return new TheoryDataRow<int, string>(12, "book");
yield return new TheoryDataRow<int, string>(9, "magnifying glass");
}
}
public class xUnit1007
{
[Theory]
[ClassData(typeof(xUnit1007_TestData))]
public void TestMethod(int quantity, string productType)
{ }
}