Null should not be used for value type parameters
This rule is trigged by having a null
value in your [InlineData]
for a value type parameter.
Value types are incompatible with null
values.
To fix a violation of this rule, you may:
null
value with a non-null
valueusing Xunit;
public class xUnit1012
{
[Theory]
[InlineData(null)]
public void TestMethod(int _) { }
}
If nullable reference types are enabled, this also violates:
using Xunit;
public class xUnit1012
{
[Theory]
[InlineData(null)]
public void TestMethod(object _) { }
}
using Xunit;
public class xUnit1012
{
[Theory]
[InlineData(42)]
public void TestMethod(int _) { }
}
using Xunit;
public class xUnit1012
{
[Theory]
[InlineData(null)]
public void TestMethod(int? _) { }
}
If nullable reference types are enabled, parameters must be decorated to receive null
values:
using Xunit;
public class xUnit1012
{
[Theory]
[InlineData(null)]
public void TestMethod(object? _) { }
}