如何在我的项目中的所有测试文件上运行 go test,供应商包除外 [英] How to run go test on all test files in my project except for vendor packages

查看:20
本文介绍了如何在我的项目中的所有测试文件上运行 go test,供应商包除外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目文件夹包含:

Makefile  README.md  component/  driver/  service/  vendor/  worker/

我想对所有测试文件运行 go test,例如foobar_test.go 文件,供应商包中的测试文件除外.我最接近成功的是 go test ./... 但它包括供应商测试文件.

I'd like to run go test on all test files, e.g. foobar_test.go files except for the test files in the vendor package. The closest I've come to success was with go test ./... but that included vendor test files.

我在文档中看到您可以将正则表达式传递给 -run 选项,但我无法让它正常工作.例如我试过go test ./*,但是我得到一堆can't load package errors.

I saw in the documentation you can pass a regex to -run option but I'm having trouble getting this working. For example I tried go test ./*, but I get a bunch of can't load package errors.

最好的方法是什么?

推荐答案

-run 模式只匹配测试标识符(不是文件名);原则上你可以这样做:

The -run pattern is matched only against the test identifier (not the filename); in principle you could do:

go test -run TestFoo

但是当您必须将 Foo 添加到所有测试函数名称时,您可能不希望这样做.

but when you'd have to add Foo to all your test function names, which you probably don't want.

... 通配符从 Go 1.9 开始排除 ./vendor 目录,所以你现在可以运行 go test ./...code> 并且它不会包含 ./vendor.

The ... wildcard excludes the ./vendor directory since Go 1.9, so you can now just run go test ./... and it won't include ./vendor.

这篇关于如何在我的项目中的所有测试文件上运行 go test,供应商包除外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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