Sto cercando di capire come eseguire il test correttamente eccezioni con FsUnit. membri Gazzetta di documentazione, che per testare le eccezioni devo proprio qualcosa di simile:Come testare correttamente eccezioni con FsUnit
(fun() -> failwith "BOOM!" |> ignore) |> should throw typeof<System.Exception>
Ma, se non segnalare il mio metodo di prova con [<ExpectedException>]
attributo sarà sempre esito negativo. Sembra ragionevole perché se vogliamo testare le eccezioni dobbiamo aggiungere tale attributo in C# + NUnit.
Ma, fino a quando ho aggiunto questo attributo non importa che tipo di eccezione che sto cercando di buttare, sarà sempre gestito.
Alcuni frammenti: miei LogicModule.fs
exception EmptyStringException of string
let getNumber str =
if str = "" then raise (EmptyStringException("Can not extract number from empty string"))
else int str
miei LogicModuleTest.fs
[<Test>]
[<ExpectedException>]
let``check exception``()=
(getNumber "") |> should throw typeof<LogicModule.EmptyStringException>
FYI - con Unquote, https://code.google.com/p/unquote/, si asserire che 'getNumber" "' nel tuo ultimo esempio solleva l'eccezione prevista come 'solleva<@ getNumber" "@ > ' –