Sto provando a scrivere alcuni test NUnit in F # e ho problemi a passare una funzione allo ThrowsConstraint
. Un campione distillato (non) funzionante è sotto.Come si passa una funzione a NUnit Throws Constraint?
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>())
Questo compila bene, ma ottengo il seguente dal test corridore NUnit:
FsTest.Tests.Example.foo:
System.ArgumentException : The actual value must be a TestDelegate but was [email protected]
Parameter name: actual
Mentre io sono in grado di aggirare il problema mediante l'attributo ExpectedException
, la mia domanda è che cosa è la corretta modo di usare una funzione F # in questa situazione?
Grazie mille per la spiegazione. –
Bello, la sua buona soluzione, perché in F # (VS 2010) l'approccio degli attributi non funzionava per me (ho provato a marcare il metodo di prova con l'attributo ExpectedException e non ha funzionato affatto) Grazie! – Roboblob