简体   繁体   English

使用FsUnit.Xunit声明异常消息

[英]Asserting exception message using FsUnit.Xunit

I'm trying to assert a certain exception type and message using FsUnit.Xunit. 我正在尝试使用FsUnit.Xunit声明某种异常类型和消息。 There is some throwWithMessage function that comes with FsUnit. FsUnit附带了一些throwWithMessage函数。 However, when using it instead of the throw function fsc emits the following errors: 但是,当使用它而不是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'

This is the test that won't compile: 这是无法编译的测试:

[<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

I'm not sure what's wrong here. 我不确定这是怎么回事。

Versions: 版本:

  • FsUnit/FsUnit.Xunit 3.1.0 FsUnit / FsUnit.Xunit 3.1.0
  • NHamcrest (as referenced by FsUnit.Xunit) 2.0.1 NHamcrest(由FsUnit.Xunit引用)2.0.1
  • Xunit 2.3.1 Xunit 2.3.1

Welp, I missed some brackets. 威尔普,我错过了一些花括号。 This works: 这有效:

[<Fact>]
let ``Some test`` () =
    (fun () -> This.Throws("a", 10) |> ignore)
    |> should (throwWithMessage "Some message") typeof<ArgumentException> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM