2015-02-10 87 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