F#中的Expecto测试即使在被迫失败时也总是通过
问题描述:
我试图在我们的测试项目中获得并期望运行。F#中的Expecto测试即使在被迫失败时也总是通过
虽然它编译和运行良好,但我想确保它确实工作。所以我给了它一个失败的案例,它通过。
我在这里错过了一些愚蠢的东西吗?从测试
[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. ᕙ໒(˵ ಠ ╭͜ʖ╮ ಠೃ ˵)७ᕗ
答
我的测试设置
let tests =
testList "Test Group" [
test "Testing fail test" {
let result = false
Expecto.Expect.isTrue result
}
]
let runTests args =
runTestsWithArgs defaultConfig args tests
输出所有的Expecto.Expect
函数采用一个串参数以可被打印在失败消息的结束。您没有提供该参数,因此您的Expecto.Expect.isTrue result
表达式的类型为string -> unit
:它实际上尚未调用isTrue
。 (您应该在IDE中的该表达式下看到一条绿色波浪线,表示该值将被忽略)。向您的呼叫中添加一个字符串,例如Expecto.Expect.isTrue result "should fail"
,然后您的测试将按其应有的顺序进行。
是的,修复它....谢谢 –
此外,通常是一个好主意,“警告作为错误”编译。 –