我正在使用FsUnit 2.1(使用NUnit 3.2)为F#项目编写测试.这是一个简单的模块:
namespace Library1
module LibraryFunctions =
let Execute f1 = f1()
let Id x = x
Run Code Online (Sandbox Code Playgroud)
这是我的测试:
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
Run Code Online (Sandbox Code Playgroud)
第二次测试失败(在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#interop的一些问题.如果是这样,怎么解决?