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

时间:2016-03-26 17:15:25

标签: f# nunit missingmethodexception fsunit

我正在使用FsUnit 2.1(使用NUnit 3.2)为F#项目编写测试。这是一个简单的模块:

public static void main(String[] args) {
    MyListener mm = new MyListener();
    try {
        SwingUtilities.invokeAndWait(new Runnable() {
            @Override
            public void run() {
                Timer t = new Timer(1000, mm);
                mm.setTimer(t);
                t.start();
            }
        });
    } catch (InvocationTargetException | InterruptedException e) {
        e.printStackTrace();
    }
}

以下是我的测试:

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

第二次测试失败(在NCrunch和ReSharper中),消息为:

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

如果我将测试中的模块放在与测试相同的代码文件中(而不是在单独的VS项目中),则测试通过。我怀疑这是由于NUnit和F#/ C#interop的一些问题。如果是这样,怎么解决?

1 个答案:

答案 0 :(得分:5)

这是FsUnit和其他项目的已知问题(请参阅herehere)。

作为解决方法,您可以将其添加到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>

注意:您需要将4.3.0.0更新为您的FsUnit程序集正在使用的FSharp.Core版本,以及何时更新。

相关问题