简体   繁体   English

FsUnit不会匹配异常-F#

[英]FsUnit won't match exception - F#

I am trying to assert an exception using FsUnit built upon XUnit. 我正在尝试使用基于XUnit构建的FsUnit断言异常。 I have taken this test from the FsUnit website : 我已经从FsUnit网站进行了此测试:

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

I am using Resharper 2016 to run the test and I get the following error: 我正在使用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

I am using the following versions of the libraries involved: 我正在使用以下版本的库:

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

I thought it might be a problem with XUnit so I tried switching to use FsUnit based on NUnit with the following test: 我以为XUnit可能有问题,所以我尝试通过以下测试切换为使用基于NUnit的FsUnit:

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

The NUnit version throws a MissingMethodException : NUnit版本抛出MissingMethodException

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

Any help would be greatly appreciated as I am at my wits end with this. 任何帮助将不胜感激,因为我不知所措。

I have figured this out. 我已经弄清楚了。 To get the test to work I needed to use FsUnit based on NUnit and downgrade FSharp to use FSharp 3.1.2.5. 为了使测试正常进行,我需要使用基于NUnit的FsUnit,并将FSharp降级以使用FSharp 3.1.2.5。 If you use FsUnit based on NUnit and FSharp 4.0.0.1 then you get the dreaded MissingMethodException . 如果您使用基于NUnit和FSharp 4.0.0.1的FsUnit,则会得到可怕的MissingMethodException

I could not figure out why the code did not work on FsUnit.Xunit. 我不知道为什么代码不能在FsUnit.Xunit上运行。

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

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