首页 > 解决方案 > 如何在运行“go test”时排除或跳过特定目录

问题描述

go test $(go list ./... | grep -v /vendor/) -coverprofile .testCoverage.txt

我正在使用上述命令来测试文件,但是我想从测试中排除 1 个名为“Store”的文件夹。怎么做?

标签: gotestinggoland

解决方案


你已经在这样做了:

$(go list ./... | grep -v /vendor/)

grep -v /vendor/部分是排除/vendor/目录。因此,只需对您的Store目录执行相同操作:

go test $(go list ./... | grep -v /Store/) -coverprofile .testCoverage.txt

请注意,/vendor/不需要排除这种方式(除非您使用的是非常旧的 Go 版本)。如果您使用的是旧版本的 Go,您可以将它们组合起来:

go test $(go list ./... | grep -v /vendor/ | grep -v /Store/) -coverprofile .testCoverage.txt

推荐阅读