在我的项目中,我有多个包和子目录。在顶部目录中,我可以运行,它运行所有子目录中的所有测试。我已经阅读了很长一段时间,关于如何只测试与给定模式或测试名称匹配的测试,但无法找到解决方案。通过浏览这些(1 2 3和godocs),我想我可以使用这个:go test ./...
go test ./... -run mypattern
运行与 mypattern 匹配的测试,但对我来说,它运行所有测试。现在,我正在使用cd,查找和grep的组合来运行符合我标准的测试。
你可以试试这个:
git clone https://github.com/grafana/grafana-plugin-sdk-go.git
> go test -run TestJSON
=== RUN TestJSONNotice
=== RUN TestJSONNotice/notice_with_severity_and_text
--- PASS: TestJSONNotice (0.00s)
--- PASS: TestJSONNotice/notice_with_severity_and_text (0.00s)
=== RUN TestJSON
=== RUN TestJSON/json.Unmarshal_and_json.Marshal
=== RUN TestJSON/json.Unmarshal_and_json.Marshal/Should_run_without_error
=== RUN TestJSON/json.Unmarshal_and_json.Marshal/Should_create_equal_data
--- PASS: TestJSON (0.00s)
--- PASS: TestJSON/json.Unmarshal_and_json.Marshal (0.00s)
--- PASS: TestJSON/json.Unmarshal_and_json.Marshal/Should_run_without_error (0.00s)
--- PASS: TestJSON/json.Unmarshal_and_json.Marshal/Should_create_equal_data (0.00s)
PASS
ok github.com/grafana/grafana-plugin-sdk-go/data 0.016s
> cd data
> go test -run *TestJSON*
zsh: no matches found: *TestJSON*
> go test -run ^TestJSON*
zsh: no matches found: ^TestJSON*
> go test -v -cover --short -race ./... -run ^TestFloatAt*
zsh: no matches found: ^TestFloatAt*
有人可以告诉我如何只测试与给定模式或测试名称匹配的测试吗?
互换的青春
相关分类