shouldFail with "unexpected result" instead of ignore
See original GitHub issueDescription
Using shouldFail
is a little bit tedious when it comes to having to use ignore
.
In my opinion, would be nice if shouldFail
could take a function that had a return value (i.e. unit -> 'a
) and then use that return value in the error message if the test would fail.
Repro steps
-
Create MyTests.fs
-
Insert code:
module MyTests open System open NUnit.Framework open FsUnitTyped [<TestCase("foo")>] [<TestCase("42")>] // valid int, shouldFail will trigger let ``Throws on invalid int`` input = // want to do: // let operation () = Convert.ToInt32 input let operation () = Convert.ToInt32 input |> ignore shouldFail operation [<Test>] let ``Parses int`` () = Convert.ToInt32 "123" |> shouldEqual 123
-
Run tests
Expected behavior
Error from first test should show:
Throws on invalid int("42")
Source: UtilityTests_Math.fs line 13
Duration: 53 ms
Message:
System.Exception : Operation did not fail.
Unexpected result: 42
Stack Trace:
TopLevelOperators.shouldFail[exn](FSharpFunc`2 f)
UtilityTests_Math.Throws on invalid int(String input) line 13
Actual behavior
Error thrown:
Throws on invalid int("42")
Source: UtilityTests_Math.fs line 13
Duration: 53 ms
Message:
System.Exception : Operation did not fail.
Stack Trace:
TopLevelOperators.shouldFail[exn](FSharpFunc`2 f)
UtilityTests_Math.Throws on invalid int(String input) line 13
Related information
- Operating system: Windows
- FsUnitTyped: 2.3.2
- .NET Runtime, CoreCLR or Mono Version: .NET 4.5.1
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Should a program fail on errors or silently ignore them
Whether the program should fail or not depends a lot on the context. ... If it is an unexpected error, then your program...
Read more >Testng on IntelliJ no output after tests are ignored
but ignoring tests is a bad practice. And test SHOULD fail and stop the execution on unexpected exceptions!
Read more >How do I ignore errors in the play however it should fail at ...
Use ignore_errors : true for tasks you want to continue, but save their status with register . Then at the end of the...
Read more >An unexpected call to one of the method of a mock doesn't ...
I only mix it into my test suite. This workaround both reports the unexpected calls directly as well as records them and at...
Read more >Investigating JUnit 5 asserts - Alexander on Test
3 should fail until we use 'equalsIgnoreCase'; 4 should always fail. To avoid too much code, and allow me to see the results...
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
@jilleJr You can close this issue. There is no plan to do it. Actually, there is no great need to use it. There are more ways to test code using other operators.
Oki ^^