Edit on GitHub

xUnit1012   v2 v3   Warning

Null should not be used for value type parameters

Cause

This rule is trigged by having a null value in your [InlineData] for a value type parameter.

Reason for rule

Value types are incompatible with null values.

How to fix violations

To fix a violation of this rule, you may:

Examples

Violates

using 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 _) { }
}

Does not violate

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? _) { }
}
Copyright © .NET Foundation. Contributions welcomed at https://github.com/xunit/xunit/tree/gh-pages.