Matt Joiner
Matt Joiner

Reputation: 118660

List tests but don't run them

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.

Upvotes: 2

Views: 227

Answers (2)

Mr_Pink
Mr_Pink

Reputation: 109442

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.

Upvotes: 3

Duru Can Celasun
Duru Can Celasun

Reputation: 1681

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+';

Upvotes: 1

Related Questions