Edit on GitHub

xUnit1008 Warning

Test data attribute should only be used on a Theory

Cause

This is triggered by forgetting to put the [Theory] attribute on a test method with data attributes.

Reason for rule

If the test method does not have a [Theory] attribute on it, then the test will not run.

How to fix violations

To fix a violation of this rule, either:

Examples

Violates

using Xunit;

public class xUnit1008
{
    [InlineData(42)]
    public void TestMethod(int _) { }
}

Does not violate

using Xunit;

public class xUnit1008
{
    [Theory]
    [InlineData(42)]
    public void TestMethod(int _) { }
}
using Xunit;

public class xUnit1008
{
    public void TestMethod(int _) { }
}

How to suppress violations

#pragma warning disable xUnit1008 // Test data attribute should only be used on a Theory
#pragma warning restore xUnit1008 // Test data attribute should only be used on a Theory
Copyright © .NET Foundation. Contributions welcomed at https://github.com/xunit/xunit/tree/gh-pages.