CLI tool that outputs tests and subtests outline of a go test source file in JSON format.
go install github.com/devuo/gotestoutline@latest
> gotestoutline file_test.go
This will write an output like the following to stdout:
[
{
"name": "TestMain"
"type": "test",
"path": [],
"lbrace": 123,
"rbrace": 458
},
{
"name": "Succeeds",
"type": "subtest",
"path": ["TestMain"],
"lbrace": 138,
"rbrace": 235,
},
{
"name": "Succeeds (With Option)",
"type": "subtest",
"path": ["TestMain", "Succeeds"],
"lbrace": 140,
"rbrace": 210,
},
{
"name": "Fails",
"type": "subtest",
"path": ["TestMain"],
"lbrace": 138,
"rbrace": 189,
}
]
const (
TestType Type = "test"
SubtestType Type = "subtest"
DynamicSubtestType Type = "dynamicsubtest"
)
type Test struct {
// Name of the test
Name string `json:"name"`
// Type of test
Type Type `json:"type"`
// Path to this test, including parent test names
Path []string `json:"path"`
// Character position of the test opening brace / parenthesis
LBrace int `json:"lbrace"`
// Character position of the test closing brace / parenthesis
RBrace int `json:"rbrace"`
}