为什么`测试 - 运行NotExist`传递? [英] Why does `go test -run NotExist` pass?

查看:85
本文介绍了为什么`测试 - 运行NotExist`传递?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我运行以下命令:

  go test -run NotExist 

答案是PASS。我认为我的测试文件不包含一个名为 TestNotExist 的测试,我希望上面的命令返回FAIL

解决方案如果没有 -run 选项 go test 则运行所有测试。您可以使用 -run 选项来不运行所有测试;将过滤掉,排除 测试(并且您以形式要求不可排除测试的名称匹配 / em>正则表达式模式 - 但这与讨论的点无关):

命令行,测试包:


默认情况下,go测试不需要参数。它使用当前目录中的源代码编译和测试软件包,包括测试,并运行测试。

测试标志说明:


  -run regexp 
只运行符合正则表达式的测试和示例。


这是一个完美的正常结果,所有的测试,即仍然需要执行的一组测试中仍然没有测试。



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


If I run the following

go test -run NotExist

The response is PASS. Seeing as my test file does not contain a test called TestNotExist I would expect the command above to return FAIL

解决方案

Without the -run option go test runs all tests. You use the -run option to not run all tests; to filter out, to exclude tests (and you do this in the form of requiring names of non-excludable tests to match a regexp pattern - but this is irrelevant form the point of discussion):

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.

It is a perfectly "normal" outcome that a filtering filters out all tests, that no tests remains in the set of tests that still need to be executed.

When no tests FAIL, it is considered as the test run PASSes. If no tests match, no tests will run and no tests will FAIL, and thus the test run will PASS.

这篇关于为什么`测试 - 运行NotExist`传递?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆