I'm trying to write some unit tests in F# with xUnit2 and AutoFixture and I'm facing a problem. I have a Theory with custom attributes that inherits from InlineAutoData and the Test Explorer keeps saying me that no tests was found. If I replace the Theory attribute by a Fact attribute it still doesn't work but if I remove the custom InlineData attributes the test is discovered. Tests are written in F# but attributes are in C# in another project.
I have found this StackOverflow question which seems similar but it doesn't help me solving my problem : AutoFixture in F# UnitTest Project Not Displaying Unit Tests in Test Explorer
Here is the unit test declaration:
[<Theory>]
[<SyntaxTreeInlineAutoData("Class/SingleClass.cs", 1)>]
[<SyntaxTreeInlineAutoData("Class/MultipleClass.cs", 2)>]
[<SyntaxTreeInlineAutoData("Class/NestedClass.cs", 2)>]
let ``Inspect_WhenVariousContexts_WithSuccess`` (count, tree : SyntaxTree) =
Here is attributes declarations:
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public class SyntaxTreeInlineAutoDataAttribute : InlineAutoDataAttribute
{
#region Constructors
public SyntaxTreeInlineAutoDataAttribute(string sourceFile, params object[] values)
: base(new SyntaxTreeAutoDataAttribute(sourceFile), values)
{
}
#endregion
}
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public class SyntaxTreeAutoDataAttribute : AutoDataAttribute
{
#region Constructors
public SyntaxTreeAutoDataAttribute() : this(null)
{
}
public SyntaxTreeAutoDataAttribute(string sourceFile)
: base(new Fixture().Customize(new SyntaxTreeCustomization(sourceFile)))
{
}
#endregion
}
[Edit]
The project is a port of a C# project. Unit tests was working fine with the custom attribute. The bug only occurred with tests write in F#.
Everything is installed : xUnit2, xUnit.runners.visualstudio and AutoFixture.
Thanks for the help.