Edit on GitHub

xUnit1009   v2 v3   Error

InlineData values must match the number of method parameters

Cause

This rule is triggered when you don’t have enough test data in your [InlineData] attribute to match the number of parameters on your test method.

Reason for rule

A theory which has insufficient data to cover all the tests will fail when you attempt to run it because of the missing data.

How to fix violations

To fix a violation of this rule, you may:

Examples

Violates

using Xunit;

public class xUnit1009
{
    [Theory]
    [InlineData("Hello world")]
    public void TestMethod(string greeting, int age) { }
}

Does not violate

using Xunit;

public class xUnit1009
{
    [Theory]
    [InlineData("Hello world", 42)]
    public void TestMethod(string greeting, int age) { }
}
using Xunit;

public class xUnit1009
{
    [Theory]
    [InlineData("Hello world")]
    public void TestMethod(string greeting) { }
}
using Xunit;

public class xUnit1009
{
    [Theory]
    [InlineData("Hello world")]
    public void TestMethod(string greeting, int age = 42) { }
}
Copyright © .NET Foundation. Contributions welcomed at https://github.com/xunit/xunit/tree/gh-pages.