3

I'm playing with unit testing in F#. I'm running Visual Studio 2013 Community Edition. I created a test project and installed NUnit 2.6.4 and FsUnit 1.3.0.1. I used Package Manager Console. I added references to the libraries in the project and in my script file I referenced the DLLs and added open clauses:

#r @"C:\Users\pw\Documents\Visual Studio 2013\Projects\FSharpForQuantFirst\packages\FsUnit.1.3.0.1\Lib\Net40\FsUnit.NUnit.dll"
#r @"C:\Users\pw\Documents\Visual Studio 2013\Projects\FSharpForQuantFirst\packages\NUnit.2.6.4\lib\nunit.framework.dll" 

open NUnit.Framework
open NUnit.Framework.Constraints
open FsUnit

1 |> should equal 1

There are no errors nor warnings in my code. However, when I run the code in F# Interactive the last line triggers the following error:

Test.fsx(8,6): error FS0074: The type referenced through 'NUnit.Framework.Constraints.Constraint' is defined in an assembly that is not referenced. You must add a reference to assembly 'nunit.framework'.

But I've already added the reference to nunit.framework.

I cleaned the project, reinstalled the packages, removed and added references, but the result is the same. I still get the error. Any idea what's the problem and how to solve it?

Guy Coder
  • 24,501
  • 8
  • 71
  • 136
PiotrWolkowski
  • 8,408
  • 6
  • 48
  • 68

1 Answers1

2

If you may have noticed, there is a app.config with binding redirects for nunit.framework.

<?xml version="1.0" encoding="utf-8"?>
<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.1.0" newVersion="4.3.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="nunit.framework" publicKeyToken="96d09a1eb7f44a77" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.6.4.14350" newVersion="2.6.4.14350" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

F# Interactive doesn't take this one into account and therefore you have to use NUnit 2.6.3 which is referenced by FsUnit.NUnit.dll.

Please downgrade NUnit to 2.6.3 and be sure to reset the F# Interactive session.

ildjarn
  • 62,044
  • 9
  • 127
  • 211
Max Malook
  • 513
  • 3
  • 9