我想写一些单元测试的F#与xUnit2和AutoFixture,我面临一个问题。我有一个从InlineAutoData继承自定义属性的理论,并且测试资源管理器一直说我没有找到测试。如果我用Fact属性替换Theory属性,它仍然不起作用,但如果我删除自定义InlineData属性,则会发现测试。测试用F#编写,但属性在另一个项目中用C#编写。F#理论与自定义AutoFixture.InlineAutoData不显示在测试资源管理器
我发现这个StackOverflow的问题,这似乎是相似的,但它并不能帮助我解决我的问题:AutoFixture in F# UnitTest Project Not Displaying Unit Tests in Test Explorer
这里是单元测试声明:
[<Theory>]
[<SyntaxTreeInlineAutoData("Class/SingleClass.cs", 1)>]
[<SyntaxTreeInlineAutoData("Class/MultipleClass.cs", 2)>]
[<SyntaxTreeInlineAutoData("Class/NestedClass.cs", 2)>]
let ``Inspect_WhenVariousContexts_WithSuccess`` (count, tree : SyntaxTree) =
下面是属性声明:
[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
}
[编辑]
该项目是C#项目的一个端口。单元测试与自定义属性一起工作正常。该错误仅在使用F#编写测试时发生。
所有安装:xUnit2,xUnit.runners.visualstudio和AutoFixture。
感谢您的帮助。
你有做任何C#测试曝光机会?你安装了xUnit Visual Studio亚军? –
我的[自我回答半相关问题](http://stackoverflow.com/questions/35103781/why-is-the-visual-studio-2015-test-runner-not-discovering-my-xunit-v2-测试/ 35103782#35103782)与F#,xUnit和VS2015(但不是AutoFixture) –