列出测试但不运行它们。

huangapple go评论82阅读模式
英文:

List tests but don't run them

问题

你可以使用go list命令来列出可用于go test的测试,而不运行它们。以下是示例命令:

go list ./...

这将列出当前目录及其子目录中的所有测试。你可以根据需要调整路径参数来指定特定的包或目录。

希望这可以帮助到你!

英文:

How do I list the tests available to go test without running them? I want to know what tests (including subtests) are present so I can manually pick a subset of them to run with a later command. I would expect something like go test -l or go test -n for something like this.

答案1

得分: 3

在go1.9中,go test命令接受一个新的-list标志,该标志以正则表达式作为参数,并将与之匹配的任何测试、基准测试或示例的名称打印到标准输出,而不运行它们。

test flags documentation 可以在 https://tip.golang.org 上找到,直到官方go1.9版本发布为止。

英文:

In go1.9 the go test command accepts a new -list flag, which takes a regular expression as an argument and prints to stdout the name of any tests, benchmarks, or examples that match it, without running them.

The test flags documentation can be found under https://tip.golang.org until the official go1.9 release.

答案2

得分: 1

没有go子命令可以实现这个,但是你可以通过一点点的findgrep(GNU版本,用于-P标志)魔法来实现:

find /path/to/your/project -not -path "./vendor" -type f -name "*_test.go" -exec cat {} \; | grep -oP '^func (\w+)\(\w \*testing\.T\) {$' | grep -oP ' \w+' | grep -oP '\w+';
英文:

There is no go subcommand for that, but you can do it with a little bit of find and grep (GNU version, for the -P flag) magic:

find /path/to/your/project -not -path "./vendor" -type f -name "*_test.go" -exec cat {} \; | grep -oP '^func (\w+)\(\w \*testing\.T\) {$' | grep -oP ' \w+' | grep -oP '\w+';

huangapple
  • 本文由 发表于 2017年6月13日 12:21:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/44512343.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定