英文:
How to selective test go modules with go test?
问题
我正在一个庞大的遗留代码库中工作,其中有很多破损的测试,导致运行go test ./...
返回了很多失败的测试,而我现在不想专注于这些测试。
我尝试使用+build
来针对特定的子包进行测试,但它运行了所有未配置的测试。目前,我不能选择浏览所有的测试。
目前,我只能通过以下方式进行测试:
go test \
-coverprofile=coverage.out \
-tags=moduleB_feature1,moduleA_feature1,moduleA_feature3 \
code_dir/projectX/moduleA/... \
code_dir/projectY/moduleB/feature1
是否有一个命令可以让我忽略所有未配置+build
的测试,这样我就可以使用./...
?
英文:
I'm working in a large legacy codebase with lots of broken tests making running go test ./...
returning a lot of failed tests that I don't want to focus on right now.
I tried using +build
which is good enough for targeting certain sub-package but it runs all of the test not configured as well. Going through all the tests right now is not an option for me.
Currently I have to do it the long way with:
go test \
-coverprofile=coverage.out \
-tags=moduleB_feature1,moduleA_feature1,moduleA_feature3 \
code_dir/projectX/moduleA/... \
code_dir/projectY/moduleB/feature1
Is there a command for me to ignore all the test without +build
configured so I can use ./...
?
答案1
得分: 2
你可以运行特定子包的测试。例如,如果你有一个包example.org/your/module/some/package
,那么以下命令将执行some/package
的测试:
go test example.org/your/module/some/package
它可以与通过正则表达式选择测试相结合:-run
开关
go test example.org/your/module/some/package -run `Foo`
将执行与正则表达式Foo
匹配的some/package
包中的所有测试函数,例如TestFooBar(t *testing.T)
。
英文:
You can run test for specific sub-package. E.g., if you have package example.org/your/module/some/package
then the command
go test example.org/your/module/some/package
executes tests for some/package
only.
It could be combined with selecting tests by regular expression: -run
switch
go test example.org/your/module/some/package -run `Foo`
executes all test functions from the package some/package
that match the regular expression Foo
, such as TestFooBar(t *testing.T)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论