如何对我项目中的所有测试文件(供应商包除外)运行go test [英] How to run go test on all test files in my project except for vendor packages
问题描述
我的项目文件夹包含:
Makefile README.md component/ driver/ service/ vendor/ worker/
我想在所有测试文件上运行go test
,例如foobar_test.go
文件,但供应商软件包中的测试文件除外.我最接近成功的是go test ./...
,但其中包括供应商测试文件.
我在文档中看到您可以将正则表达式传递给-run
选项,但是我无法正常工作.例如,我尝试了go test ./*
,但是却得到了一堆can't load package errors
.
做到这一点的最佳方法是什么?
-run
模式仅与测试标识符(而非文件名)匹配;原则上您可以这样做:go test -run TestFoo
但是当您必须在所有测试函数名称中添加Foo
时,您可能不希望这样做.
从Go 1.9开始,...
通配符不包含./vendor
目录,因此您现在可以运行go test ./...
,并且其中将不包含./vendor
.
My project folder contains:
Makefile README.md component/ driver/ service/ vendor/ worker/
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.
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
.
What's the best way to do this?
The -run
pattern is matched only against the test identifier (not the filename); in principle you could do:
go test -run TestFoo
but when you'd have to add Foo
to all your test function names, which you probably don't want.
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屋!