Reputation: 13836
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.
Upvotes: 16
Views: 13886
Reputation: 87
If you do not use ack
as another answer mentions, you may simply grep -r "func Test" . | wc -l
. This works because
func Test
, which should include every test func (it also includes TestMain
)-r
tells grep to look in subdirectories recursivelywc -l
will count the number of lines piped into it, which should be the number of test casesUpvotes: 1
Reputation: 6026
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.
Upvotes: 20