The type argument to TheoryData is nullable, while the type of the corresponding test method parameter is not
The TheoryData
type argument is marked as nullable, and the test method argument is marked as non-nullable.
Passing null
data to a test method that isn’t expecting it could cause runtime errors or unpredictable test results
(either false positives or false negatives).
To fix a violation of this rule, either make the TheoryData
type non-nullable, or make the test method parameter nullable.
using Xunit;
public class xUnit1040
{
public static TheoryData<string?> PropertyData =>
new() { "Hello", "World", null };
[Theory]
[MemberData(nameof(PropertyData))]
public void TestMethod(string _) { }
}
using Xunit;
public class xUnit1040
{
public static TheoryData<string> PropertyData =>
new() { "Hello", "World" };
[Theory]
[MemberData(nameof(PropertyData))]
public void TestMethod(string _) { }
}
using Xunit;
public class xUnit1040
{
public static TheoryData<string?> PropertyData =>
new() { "Hello", "World", null };
[Theory]
[MemberData(nameof(PropertyData))]
public void TestMethod(string? _) { }
}