Edit on GitHub

xUnit1023 Error

Theory methods cannot have default parameter values

Cause

One or more parameters of a theory method have default values, and you are using a version of xUnit.net < 2.2.0.

Reason for rule

Theory methods receive their test data from data attributes such as [InlineData]. xUnit.net versions < 2.2.0 require that data attributes provide values for all parameters of a theory method; any fallback default parameter values you provide would never be used. Providing default values indicates that you are making an assumption that will never be met in practice.

How to fix violations

To fix a violation of this rule, either:

Examples

Violates

class TestClass
{
    [Theory]
    [InlineData(1)]
    public void TestMethod(int arg = 0)
    {
    }
}

Does not violate

class TestClass
{
    [Theory]
    [InlineData(1)]
    public void TestMethod(int arg)
    {
    }
}
Copyright © 2017 .NET Foundation. Contributions welcomed at https://github.com/xunit/xunit.analyzers.