简体   繁体   中英

FsUnit won't match exception - F#

I am trying to assert an exception using FsUnit built upon XUnit. I have taken this test from the FsUnit website :

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

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
  • .Net : 4.6.2
  • FsUnit.Xunit : 1.4.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:

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

The NUnit version throws a 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. If you use FsUnit based on NUnit and FSharp 4.0.0.1 then you get the dreaded MissingMethodException .

I could not figure out why the code did not work on FsUnit.Xunit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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