gpt4 book ai didi

unit-testing - 为什么 `go test -run NotExist` 通过?

转载 作者:IT王子 更新时间:2023-10-29 02:13:40 27 4
gpt4 key购买 nike

如果我运行以下命令

go test -run NotExist

响应为通过。鉴于我的测试文件不包含名为 TestNotExist 的测试,我希望上面的命令返回 FAIL

最佳答案

没有 -run 选项 go test 运行所有测试。您使用 -run 选项不运行所有测试过滤掉排除测试(你以要求非排他性测试的名称​​匹配 正则表达式模式 - 但这与讨论点无关):

Command go, Test packages:

By default, go test needs no arguments. It compiles and tests the package with source in the current directory, including tests, and runs the tests.

Description of testing flags:

-run regexp
Run only those tests and examples matching the regular expression.

过滤过滤掉所有测试是一个完全“正常”的结果,没有测试留在仍然需要执行的测试集中。

当没有测试失败时,它被认为是测试运行通过。如果没有匹配的测试,则不会运行任何测试,也不会失败,因此测试运行将通过。

关于unit-testing - 为什么 `go test -run NotExist` 通过?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38463609/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com