Constructors on classes derived from FactAttribute must be public when used on test methods
A violation of this rule occurs when a test method tries to use a FactAttribute
-derived attribute through
a non-public
constructor.
Although the compiler will allow a user to call an internal
(or protected internal
) constructor, the xUnit.net
framework requires that the attribute constructor used is public.
To fix a violation of this rule, either use an existing public constructor, or change the desired constructor
to public
visibility.
using System;
using Xunit;
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class CustomFactAttribute : FactAttribute
{
internal CustomFactAttribute() { }
}
public class xUnit1043
{
[CustomFact]
public void TestMethod() { }
}
using System;
using Xunit;
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class CustomFactAttribute : FactAttribute
{
public CustomFactAttribute() { }
}
public class xUnit1043
{
[CustomFact]
public void TestMethod() { }
}