FsUnit不匹配异常 - F#

时间:2017-01-18 08:50:17

标签: f# nunit xunit fsunit

我试图使用基于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()

任何帮助都会非常感激,因为我的智慧结束了。

1 个答案:

答案 0 :(得分:3)

我已经弄明白了。为了使测试起作用,我需要使用基于NUnit的FsUnit并降级FSharp以使用FSharp 3.1.2.5。如果您使用基于NUnit和FSharp 4.0.0.1的FsUnit,那么您将获得可怕的MissingMethodException

我无法弄清楚为什么代码不适用于FsUnit.Xunit。

相关问题