运行测试并跳过一些软件包 [英] Running tests and skipping some packages

查看:84
本文介绍了运行测试并跳过一些软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以跳过测试目录.例如,给定以下结构,是否可以测试mypackage,mypackage/other和mypackage/net,但不能测试mypackage/scripts?我的意思是不为每个编写Go测试命令( 例如去测试去测试网;去测试其他)

Is it possible to skip directories from testing. For example given the structure below is it possible to test mypackage, mypackage/other and mypackage/net but not mypackage/scripts? I mean without to write a go test command for each ( e.g. go test; go test net; go test other)

mypackage
mypackage/net
mypackage/other
mypackage/scripts

推荐答案

Go test接受了要在命令行上测试的软件包列表(请参见go help packages),因此您可以通过一次调用来测试任意一组软件包,例如所以:

Go test takes a list of packages to test on the command line (see go help packages) so you can test an arbitrary set of packages with a single invocation like so:

go test import/path/to/mypackage import/path/to/mypackage/other import/path/to/mypackage/net

或者,取决于您的外壳:

Or, depending on your shell:

go test import/path/to/mypackage{,/other,/net}

您也许可以使用有趣的go list调用作为参数(同样,取决于您的shell):

You might be able to use interesting invocations of go list as the arguments (again, depending on your shell):

go test `go list`

您的评论说您想跳过一个子目录,所以(取决于您的shell)也许是这样:

Your comment says you want to skip one sub-directory so (depending on your shell) perhaps this:

go test `go list ./... | grep -v directoriesToSkip`

与其他任何事情一样,如果您执行了很多操作,则可以使它成为shell别名/为它起任何作用.

as with anything, if you do that a lot you could make a shell alias/whatever for it.

例如,如果您要跳过测试的原因是您有经常要跳过的长时间/昂贵的测试,则测试本身可能/应该检查 t.Skip() .

If the reason you want to skip tests is, for example, that you have long/expensive tests that you often want to skip, than the tests themselves could/should check testing.Short() and call t.Skip() as appropriate.

然后您可以运行:

go test -short import/path/to/mypackage/...

或在mypackage目录中:

go test -short ./...

您也可以使用testing.Short()以外的其他内容来触发跳过.

You can use things other testing.Short() to trigger skipping as well.

这篇关于运行测试并跳过一些软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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