使用“ go test”列出所有测试案例

With go test -v pattern I can select and only run the tests that matches a pattern, but is there any way that I can list all test cases without run them. There is this case that the project just handed over to me has a lot of test case and I need to select some tests to run. I know greping the sources xxx_test.go is a way but is there more elegant way? I mean, each test has its meta data stored in some where, right? as the tests are required to be in a specific signature(func TestXXX(*testing.T)). This meta data can be used to do this kind of work.

There's no saved metadata, grepping is the only way pretty much.

If you have ack, you can easily use something like this:

➜ ack 'func Test[^(]+'

Just saw this in the Go1.9 release notes (draft) and I think could be what you are looking for

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.