Search code examples
f#monoexpecto

Expecto Test in F# always passes even when forced to fail


I'm trying to get expecto up and running in our test project.

Though it compiles and run fine, I wanted to just make sure it was really working. So I gave it a fail case and it passes.

Did I miss something silly here?

My test setup

let tests =
    testList "Test Group" [
        test "Testing fail test" {
           let result = false
           Expecto.Expect.isTrue result 
        }
    ]

let runTests args =
  runTestsWithArgs defaultConfig args tests

Output from the test

[08:52:06 INF] EXPECTO? Running tests...
[08:52:06 INF] EXPECTO! 1 tests run in 00:00:00.0569286 – 1 passed, 0 ignored, 0 failed, 0 errored. ᕙ໒( ˵ ಠ ╭͜ʖ╮ ಠೃ ˵ )७ᕗ

Solution

  • All the Expecto.Expect functions take a string parameter at the end that is the message to print on failure. You're not supplying that parameter, so your Expecto.Expect.isTrue result expression has the type string -> unit: it hasn't actually called isTrue yet. (You should see a green wavy line under that expression in your IDE saying that the value is ignored). Add a string to your call, like Expecto.Expect.isTrue result "should fail" and then your test will fail as it's supposed to.