2015-02-10 84 views
3

我正在玩F#中的单元测试。我正在运行Visual Studio 2013社区版。我创建了一个测试项目并安装了NUnit 2.6.4FsUnit 1.3.0.1。我使用包管理器控制台。我添加引用到库中的项目,并在我的脚本文件我引用的DLL文件,并添加open条款:F#单元测试:nunit.framework程序集未引用错误

#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 

有我的代码没有错误,也没有警告。然而,当我运行F#互动的代码的最后一行触发以下错误:

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' .

但我已经添加了参考nunit.framework

我清理了项目,重新安装了软件包,删除并添加了引用,但结果是一样的。我仍然得到错误。任何想法是什么问题以及如何解决它?

回答

2

如果您可能已经注意到,有一个app.config绑定重定向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#互动没有考虑这个考虑,因此你必须使用NUnit 2.6.3这是由FsUnit.NUnit.dll引用。

请将NUnit降级至2.6.3,并务必重置F#Interactive会话。

+0

我卸载了'NUnit 2.6.4'和安装的版本'2.6.3'。但我仍然得到相同的错误... – PiotrWolkowski 2015-02-11 01:00:09

+0

有相同的错误 – fbehrens 2015-07-08 16:40:28