Edit on GitHub

xUnit1032 Error

Test classes cannot be nested within a generic class

Cause

Test classes cannot be nested within a generic class.

Reason for rule

Generic types must be instantiated with types provided, which xUnit.net cannot provide. Test classes embedded within generic types, therefore, cannot be instantiated or executed.

How to fix violations

To fix a violation of this rule, move the test class outside the scope of the generic type.

Examples

Violates

using Xunit;

public class GenericClass<T>
{
    public class TestClass
    {
        [Fact]
        public void TestMethod() { }
    }
}

Does not violate

using Xunit;

public class GenericClass<T>
{
}

public class TestClass
{
    [Fact]
    public void TestMethod() { }
}
Copyright © .NET Foundation. Contributions welcomed at https://github.com/xunit/xunit/tree/gh-pages.