相关疑难解决方法(0)

测试带有函数参数的函数时出现MissingMethodException

我正在使用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的一些问题.如果是这样,怎么解决?

f# nunit missingmethodexception fsunit

4
推荐指数
1
解决办法
498
查看次数

标签 统计

f# ×1

fsunit ×1

missingmethodexception ×1

nunit ×1