5

I'm trying to use unquote with NUnit as the test runner. The test case is taken from Getting Started and works as expected when run outside of NUnit:

namespace FsTest.Tests

open NUnit.Framework
open Swensen.Unquote

[<TestFixture>]
module Example =

    [<Test>]
    let foo() = 
        test <@ (1+2)/3 = 1 @>

Under NUnit I get this exception:

FsTest.Tests.Example.foo: System.MissingMethodException : Method not found: 'System.Tuple2<Microsoft.FSharp.Collections.FSharpList1,Microsoft.FSharp.Quotations.FSharpExpr> Internal.reduceFullyAndGetLast(Microsoft.FSharp.Quotations.FSharpExpr)'.

I'd like to know if there's anything wrong with the code above and how I could make it work. Unquote's raise fail for me in the same way if that helps.

Guy Coder
  • 24,501
  • 8
  • 71
  • 136
Serge Belov
  • 5,633
  • 1
  • 31
  • 40
  • Can you please clarify what you mean by "run outside of NUnit" and "Under NUnit"? This issue looks very similar to http://stackoverflow.com/q/7828852/236255 except with the xUnit.net GUI test runner, where the OP learned he was referencing the wrong version of FSharp.Core.dll – Stephen Swensen Dec 12 '12 at 19:08
  • *"run outside of NUnit"* means using F# Interactive or a command line application from the same solution; *"Under NUnit"* means using a stock NUnit 2.6.2 GUI runner downloaded as a zip file. FScharp.Core.dll is referenced from the test assembly: ``. The whole thing is VS 2012 targeting .NET 4.5. – Serge Belov Dec 12 '12 at 19:16

1 Answers1

8

Based on the description of your problem, I suspect you need to configure your NUnit project with an FSharp.Core binding redirect from version 4.0.0.0 to version 4.3.0.0 since the latest version of Unquote is built for .NET 4.0 and your test project targets .NET 4.5.

See this Unquote issue for details. I believe your configuration would look something like

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <legacyUnhandledExceptionPolicy enabled="true" />
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity
          name="FSharp.Core"
          publicKeyToken="b03f5f7f11d50a3a"
          culture="neutral"/>
        <bindingRedirect
          oldVersion="2.0.0.0"
          newVersion="4.3.0.0"/>
        <bindingRedirect
          oldVersion="4.0.0.0"
          newVersion="4.3.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

I'm not sure exactly where you would need to put this for an NUnit project, but maybe in the config file specified through the Project Editor?

Unfortunately, I don't have VS2012 installed and so I am somewhat crippled in my ability to really diagnose this issue for you.

ildjarn
  • 62,044
  • 9
  • 127
  • 211
Stephen Swensen
  • 22,107
  • 9
  • 81
  • 136
  • 1
    Great, that helped, thanks. For those who interested, NUnit uses `.dll.config` to configure test DLLs, so that's where you put these settings. – Serge Belov Dec 13 '12 at 06:15