FsUnitで例外を正しくテストする方法を理解しようとしています。 [<ExpectedException>]
が、それは常に失敗する属性で、私は私のテストメソッドをマークしていない場合は、FsUnitで例外を正しくテストする方法
(fun() -> failwith "BOOM!" |> ignore) |> should throw typeof<System.Exception>
しかし:公式ドキュメントの状態は、それがこのような右の何かに私が持っている例外をテストします。なぜなら、例外をテストするには、C#+ NUnitでそのような属性を追加する必要があるからです。
ただし、この属性を追加している限り、どのような種類の例外をスローしようとしても問題はありません。常に処理されます。
一部抜粋: マイLogicModule.fs
exception EmptyStringException of string
let getNumber str =
if str = "" then raise (EmptyStringException("Can not extract number from empty string"))
else int str
マイLogicModuleTest.fs
[<Test>]
[<ExpectedException>]
let``check exception``()=
(getNumber "") |> should throw typeof<LogicModule.EmptyStringException>
をリターンを上げます - Unquote、https://code.google.com/p/unquote/を使用すると、 'getNumber" "は後者の例では' raise<@ getNumber "" @ > ' –