f# - FsUnit assert exception message -
how assert on exception message in fsunit? nunit:
[<test>] let shouldthrowexceptionandlog() = assert.that ((fun () -> calculator.calculate "-1"), throws.exception.with.property("message").equalto("negatives not allowed: -1"))
edit: don't care exception itself, i'd test exception message.
afaik there no out-of-the-box matcher want, it's easy enough create 1 yourself:
open nhamcrest let throwanywithmessage m = custommatcher<obj>(m, fun f -> match f | :? (unit -> unit) testfunc -> try testfunc() false | ex -> ex.message = m | _ -> false )
usage:
(fun () -> raise <| exception("foo") |> ignore) |> should throwanywithmessage "foo" // pass (fun () -> raise <| exception("bar") |> ignore) |> should throwanywithmessage "foo" // fail
Comments
Post a Comment