使用 FsUnit.Xunit 断言异常消息
Asserting exception message using FsUnit.Xunit
我正在尝试使用 FsUnit.Xunit 断言某种异常类型和消息。
FsUnit 附带了一些 throwWithMessage
函数。但是,当使用它而不是 throw
函数时,fsc 会发出以下错误:
C:\src\foo.fs(29,12): error FS0001: This expression was expected to have type '(unit -> unit) -> 'a' but here has type 'unit'
C:\src\foo.fs(29,19): error FS0001: The type ''a -> NHamcrest.Core.CustomMatcher<obj>' is not compatible with the type 'NHamcrest.IMatcher<obj>'
C:\src\foo.fs(29,12): error FS0001: This expression was expected to have type '(unit -> unit) -> 'a' but here has type 'unit'
这是无法编译的测试:
[<Fact>]
let ``Some test`` () =
(fun () -> This.Throws("a", 10) |> ignore)
|> should throwWithMessage "Some message" typeof<ArgumentException> //This is line 29
//^ column index 12 is here
//^ here is column index 19
我不确定这里出了什么问题。
版本:
- FsUnit/FsUnit.Xunit 3.1.0
- NHamcrest(由 FsUnit.Xunit 引用)2.0.1
- Xunit 2.3.1
哎呀,我漏掉了一些括号。这有效:
[<Fact>]
let ``Some test`` () =
(fun () -> This.Throws("a", 10) |> ignore)
|> should (throwWithMessage "Some message") typeof<ArgumentException>
我正在尝试使用 FsUnit.Xunit 断言某种异常类型和消息。
FsUnit 附带了一些 throwWithMessage
函数。但是,当使用它而不是 throw
函数时,fsc 会发出以下错误:
C:\src\foo.fs(29,12): error FS0001: This expression was expected to have type '(unit -> unit) -> 'a' but here has type 'unit'
C:\src\foo.fs(29,19): error FS0001: The type ''a -> NHamcrest.Core.CustomMatcher<obj>' is not compatible with the type 'NHamcrest.IMatcher<obj>'
C:\src\foo.fs(29,12): error FS0001: This expression was expected to have type '(unit -> unit) -> 'a' but here has type 'unit'
这是无法编译的测试:
[<Fact>]
let ``Some test`` () =
(fun () -> This.Throws("a", 10) |> ignore)
|> should throwWithMessage "Some message" typeof<ArgumentException> //This is line 29
//^ column index 12 is here
//^ here is column index 19
我不确定这里出了什么问题。
版本:
- FsUnit/FsUnit.Xunit 3.1.0
- NHamcrest(由 FsUnit.Xunit 引用)2.0.1
- Xunit 2.3.1
哎呀,我漏掉了一些括号。这有效:
[<Fact>]
let ``Some test`` () =
(fun () -> This.Throws("a", 10) |> ignore)
|> should (throwWithMessage "Some message") typeof<ArgumentException>