2016-04-29 59 views
2

我想写一些单元测试的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。

感谢您的帮助。

+0

你有做任何C#测试曝光机会?你安装了xUnit Visual Studio亚军? –

+0

我的[自我回答半相关问题](http://stackoverflow.com/questions/35103781/why-is-the-visual-studio-2015-test-runner-not-discovering-my-xunit-v2-测试/ 35103782#35103782)与F#,xUnit和VS2015(但不是AutoFixture) –

回答

1

我可以重现此问题,至少在我的repro中,问题是版本冲突。大多数Visual Studio测试运行程序不会告诉您,但如果您尝试使用命令行运行程序运行单元测试,则会看到报告的实际错误。

在我的清样,我解决了通过添加以下app.config文件到我的F#项目的问题:

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="xunit.core" publicKeyToken="8d05b1bb7a6fdb6c" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-2.1.0.3179" newVersion="2.1.0.3179" /> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 
</configuration> 
+0

感谢您的快速回答。它适用于appconfig。下次我遇到问题时,我会尝试从命令行启动测试。 –

相关问题