F#中的Expecto测试即使在被迫失败时也会通过

Ant*_*ell 4 mono f# expecto

我正试图在我们的测试项目中获得期望并运行.

虽然它编译并运行良好,但我想确保它确实有效.所以我给了它一个失败案例并且它通过了.

我在这里想念傻事吗?

我的测试设置

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

let runTests args =
  runTestsWithArgs defaultConfig args tests
Run Code Online (Sandbox Code Playgroud)

测试结果

[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. ??( ? ? ???? ?? ? )??
Run Code Online (Sandbox Code Playgroud)

rmu*_*unn 6

所有Expecto.Expect函数都在最后采用字符串参数,即失败时打印的消息.您没有提供该参数,因此您的Expecto.Expect.isTrue result表达式具有以下类型string -> unit:它尚未实际调用isTrue.(您应该在IDE中看到该表达式下的绿色波浪线,表示该值被忽略).添加一个字符串给你的电话,Expecto.Expect.isTrue result "should fail"然后你的测试将失败,因为它应该.

  • 此外,通过编译"警告为错误"通常是个好主意. (3认同)