【发布时间】:2016-08-24 21:39:08
【问题描述】:
我正在尝试使用 xUnit2 和 AutoFixture 在 F# 中编写一些单元测试,但我遇到了问题。我有一个从 InlineAutoData 继承的自定义属性的理论,并且测试资源管理器一直告诉我没有找到任何测试。如果我用 Fact 属性替换 Theory 属性,它仍然不起作用,但是如果我删除自定义 InlineData 属性,则会发现测试。测试是用 F# 编写的,但属性在另一个项目的 C# 中。
我发现这个 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 运行器吗?
-
我的 self-answered semi-related question 使用 F#、xUnit 和 VS2015(但不使用 AutoFixture)
标签: f# xunit.net autofixture