我想在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