4

FsUnit 2.1 (NUnit 3.2 を使用) を使用して、F# プロジェクトのテストを作成しています。以下は単純なモジュールです。

namespace Library1
module LibraryFunctions =
    let Execute f1 = f1()
    let Id x = x

そして、ここに私のテストがあります:

namespace Tests
open FsUnit
open NUnit.Framework
open Library1

[<TestFixture>]
type Tests() =

    [<Test>]
    // Passes
    member x.``LibraryFunctions.Id should return the value``() =
        LibraryFunctions.Id 42 |> should equal 42

    [<Test>]
    // Fails
    member x.``LibraryFunctions.Execute should return the result of the function``() =
        let f() = 42
        LibraryFunctions.Execute f |> should equal 42

2 番目のテストは (NCrunch および ReSharper で) 次のメッセージで失敗します。

System.MissingMethodException : Method not found: '!!0 Library1.LibraryFunctions.Execute(Microsoft.FSharp.Core.FSharpFunc`2<Microsoft.FSharp.Core.Unit,!!0>)'.

テスト対象のモジュールを (別の VS プロジェクトではなく) テストと同じコード ファイルに配置すると、テストは成功します。私の疑いでは、これは NUnit と F#/C# の相互運用性の問題によるものです。もしそうなら、どうすれば解決できますか?

4

1 に答える 1

5

これは、FsUnit およびその他のプロジェクトの既知の問題です (ここここを参照してください)。

回避策として、これを app.config ファイルに追加できます。

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

注意: FsUnit アセンブリが使用している4.3.0.0バージョンに更新する必要があります。FSharp.Core

于 2016-03-26T21:24:33.867 に答える