2016-04-29 58 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。下次我遇到問題時,我會嘗試從命令行啓動測試。 –

相關問題