我想在F#中編寫一些NUnit測試,並且無法將函數傳遞給ThrowsConstraint
。下面是蒸餾(非)工作樣品。如何將函數傳遞給NUnit引發約束?
open System.IO
open NUnit.Framework
[<TestFixture>]
module Example =
[<Test>]
let foo() =
let f = fun() -> File.GetAttributes("non-existing.file")
Assert.That(f, Throws.TypeOf<FileNotFoundException>())
這將編譯得很好,但我從NUnit的測試運行如下:
FsTest.Tests.Example.foo:
System.ArgumentException : The actual value must be a TestDelegate but was [email protected]
Parameter name: actual
雖然我可以在使用ExpectedException
屬性來解決這個問題,我的問題是什麼是正確的在這種情況下使用F#函數的方法?
非常感謝您的解釋。 –
不錯,它的好解決方案,因爲在F#(VS 2010)屬性方法不適合我(我試圖用ExpectedException屬性標記測試方法,它根本不工作) 謝謝! – Roboblob