我正在尝试在我们的测试项目中启动并运行 expecto。
尽管它编译并运行良好,但我只想确保它真的有效。所以我给了它一个失败的案例,它通过了。
我在这里错过了一些愚蠢的事情吗?
我的测试设置
let tests =
testList "Test Group" [
test "Testing fail test" {
let result = false
Expecto.Expect.isTrue result
}
]
let runTests args =
runTestsWithArgs defaultConfig args tests
测试输出
[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. ᕙ໒( ˵ ಠ ╭͜ʖ╮ ಠೃ ˵ )७ᕗ
最佳答案
所有 Expecto.Expect
函数在最后接受一个字符串参数,它是失败时要打印的消息。您没有提供该参数,因此您的 Expecto.Expect.isTrue result
表达式的类型为 string -> unit
:它实际上并没有调用 isTrue
然而。 (您应该在 IDE 中该表达式下方看到一条绿色波浪线,表示该值已被忽略)。在您的调用中添加一个字符串,例如 Expecto.Expect.isTrue result "should fail"
然后您的测试将按预期失败。
关于f# - 即使被迫失败,F# 中的 Expecto 测试也始终通过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44369419/