2016-04-29 4 views
2

xUnit2とAutoFixtureを使用してF#で単体テストを作成しようとしていますが、問題が発生しています。私はInlineAutoDataから継承したカスタム属性を持つTheoryを持っており、テストエクスプローラはテストが見つからないと私に言っています。 Theory属性をFact属性で置き換えても、それでも機能しませんが、カスタム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

:私のREPROで

は、私は私のF#プロジェクトに次のapp.configファイルを追加することで問題を解決しますか? 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テストランナーはあなたにそのことを教えてくれませんが、コマンドラインランナーで単体テストを実行しようとすると、実際のエラーが報告されます。あなたが発見したのですか任意のC#のテストを持っていますか

<?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でうまく動作します。次に問題があるときは、コマンドラインからテストを起動しようとします。 –