Using `should throw` does not show the raised exception, only the string version of the lambda
See original GitHub issueDescription
With FsUnit.XUnit
using should throw
, the report of “Expected vs Actual” shows the string version of the lambda function that was used to pass into the test.
Another issue is that, when the result type of the function-under-test is not unit
, the test will always fail with a similar vague message.
Repro steps
You can repro with this test:
// XUnit test
[<Fact>]
let ``Test raising exception`` () = task {
fun () -> failwith "help" |> ignore
|> should throw typeof<HttpRequestException> // should fail
Expected behavior
Something like this is expected, which would clearly indicate what goes wrong.
FsUnit.Xunit+MatchException : Exception of type 'FsUnit.Xunit+MatchException' was thrown.
Expected: System.Net.Http.HttpRequestException
Actual: System.Exception
Actual behavior
But this is shown instead, which suggests there wasn’t an exception at all and the type is wrong.
FsUnit.Xunit+MatchException : Exception of type 'FsUnit.Xunit+MatchException' was thrown.
Expected: System.Net.Http.HttpRequestException
Actual: <fun:Pipe #1 input at line 112@112>
Known workarounds
None that I found.
Related information
- Operating system: Win11
- Branch: latest from Nuget
- Using .NET 6.0
- Using FsUnit.Xunit
Issue Analytics
- State:
- Created a year ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Define a lambda expression that raises an Exception
@gnibbler Some context: I wanted to define a function def g(f, e) that calls f in the happy case and e if an...
Read more >AWS Lambda function errors in Java
This page describes how to view Lambda function invocation errors for the Java runtime using the Lambda console and the AWS CLI.
Read more >How to Use Python Lambda Functions
In this step-by-step tutorial, you'll learn about Python lambda functions. You'll see how they compare with regular functions and how you can use...
Read more >Exception-handling statements - throw and try, catch, finally
Use the throw statement to throw an exception. Use the try statement to catch and handle exceptions that might occur during execution of...
Read more >10.2 Exceptions
Whenever a primitive error occurs in Racket, an exception is raised. ... (but the semi-colon should be omitted if ‹continued-message› is not present)....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Great stuff, tx!
@abelbraaksma Yes, I see. It should be similar to the NUnit output, right:
I will analyse this.