首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用FsUnit.Xunit断言异常消息

使用FsUnit.Xunit断言异常消息
EN

Stack Overflow用户
提问于 2018-04-16 22:20:17
回答 1查看 393关注 0票数 3

我试图使用FsUnit.Xunit断言某种异常类型和消息。有一些throwWithMessage函数随FsUnit而来。但是,当使用它代替throw函数时,fsc会发出以下错误:

代码语言:javascript
复制
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'

这是一个不会编译的测试:

代码语言:javascript
复制
[<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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-04-16 22:38:35

韦尔普,我漏掉了一些括号。这样做是可行的:

代码语言:javascript
复制
[<Fact>]
let ``Some test`` () =
    (fun () -> This.Throws("a", 10) |> ignore)
    |> should (throwWithMessage "Some message") typeof<ArgumentException> 
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49867081

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档