The value is not convertible to the method parameter type
When you use [MemberData]
to target a method and pass that method arguments, the values must match the
type specified in the method parameters.
Passing the wrong type of value will result in your test failing because the provided data cannot be correctly passed to the method data function.
To fix a violation of this rule, fix either the data value or the parameter type.
using Xunit;
public class xUnit1035
{
public static TheoryData<string> TestData(string s) =>
new() { s };
[Theory]
[MemberData(nameof(TestData), new object[] { 2112 })]
public void TestMethod(string _)
{ }
}
using Xunit;
public class xUnit1035
{
public static TheoryData<string> TestData(int n) =>
new() { n.ToString() };
[Theory]
[MemberData(nameof(TestData), new object[] { 2112 })]
public void TestMethod(string _)
{ }
}
using Xunit;
public class xUnit1035
{
public static TheoryData<string> TestData(string s) =>
new() { s };
[Theory]
[MemberData(nameof(TestData), new object[] { "2112" })]
public void TestMethod(string _)
{ }
}