【问题标题】:FsUnit won't match exception - F#FsUnit 不会匹配异常 - F#
【发布时间】:2017-01-18 08:50:17
【问题描述】:

我正在尝试使用基于 XUnit 构建的 FsUnit 来断言异常。我已经从FsUnit website 接受了这个测试:

[<Fact>]
let ``boom`` () =
    (fun () -> failwith "BOOM!" |> ignore) |> should throw typeof<System.Exception>

我正在使用 Resharper 2016 运行测试,但出现以下错误:

FsUnit.Xunit+MatchException
Exception of type 'FsUnit.Xunit+MatchException' was thrown.
Expected: System.Exception
Actual:   was SqlJuxtFunctionalTests.Scenarios.CompareTableScenarios+boom@22
   at SqlJuxtFunctionalTests.Scenarios.CompareTableScenarios.boom() in C:\projects\SqlJuxt\src\SqlJuxtFunctional.Tests\CompareTableScenarios.fs:line 22

我正在使用以下版本的库:

  • FSharp.Core : 4.0.0.1
  • .Net : 4.6.2
  • FsUnit.Xunit:1.4.1.0
  • XUnit.core:2.1.0

我认为这可能是 XUnit 的问题,所以我尝试切换到使用基于 NUnit 的 FsUnit,并进行以下测试:

[<Test>]
let ``boom nunit`` () =
    (fun () -> failwith "BOOM!" |> ignore) |> should throw typeof<System.Exception>

NUnit 版本抛出 MissingMethodException:

System.MissingMethodException : Method not found: 'Void FsUnit.TopLevelOperators.should(Microsoft.FSharp.Core.FSharpFunc`2<!!0,!!1>, !!0, System.Object)'.
   at File1.boom()

任何帮助将不胜感激,因为我对此束手无策。

【问题讨论】:

    标签: f# nunit xunit fsunit


    【解决方案1】:

    我已经想通了。为了让测试正常工作,我需要使用基于 NUnit 的 FsUnit 并将 FSharp 降级为使用 FSharp 3.1.2.5。如果你使用基于 NUnit 和 FSharp 4.0.0.1 的 FsUnit,那么你会得到可怕的 MissingMethodException

    我不明白为什么代码在 FsUnit.Xunit 上不起作用。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多