Skip to content

Commit 8979f92

Browse files
committed
fix tool/slowest examples
1 parent 14268d4 commit 8979f92

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

README.md

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -255,33 +255,46 @@ To execute a test binary without installing Go, see
255255

256256
### Finding and skipping slow tests
257257

258-
`gotestsum tool slowest` reads a jsonfile and prints the names of slow tests, or update
259-
tests which are slower than the threshold.
260-
The list of tests is sorted by slowest to fastest.
261-
The json filecan be created with `gotestsum --jsonfile` or `go test -json`.
258+
`gotestsum tool slowest` reads [test2json output][testjson],
259+
from a file or stdin, and prints the names and elapsed time of slow tests.
260+
The tests are sorted from slowest to fastest.
261+
262+
`gotestsum tool slowest` can also rewrite the source of tests slower than the
263+
threshold, making it possible to optionally skip them.
264+
265+
The [test2json output][testjson] can be created with `gotestsum --jsonfile` or `go test -json`.
262266

263267
See `gotestsum tool slowest --help`.
264268

265-
**Example: printing a list of tests slower than 50 milliseconds**
269+
**Example: printing a list of tests slower than 500 milliseconds**
266270

267271
```
268-
gotestsum --jsonfile json.log
269-
gotestsum tool slowest --jsonfile json.log --threshold 50ms
272+
$ gotestsum --format dots --jsonfile json.log
273+
[.]····↷··↷·
274+
$ gotestsum tool slowest --jsonfile json.log --threshold 500ms
275+
gotest.tools/example TestSomething 1.34s
276+
gotest.tools/example TestSomethingElse 810ms
270277
```
271278

272279
**Example: skipping slow tests with `go test --short`**
273280

274-
Any test which runs longer than 200 milliseconds will be modified by adding a
275-
`t.Skip` when `testing.Short` is enabled.
281+
Any test slower than 200 milliseconds will be modified to add:
276282

283+
```go
284+
if testing.Short() {
285+
t.Skip("too slow for testing.Short")
286+
}
277287
```
278-
go test -json -short ./... | \
279-
gotestsum tool slowest --skip-stmt "testing.Short" --threshold 200ms
288+
289+
```sh
290+
go test -json -short ./... | gotestsum tool slowest --skip-stmt "testing.Short" --threshold 200ms
280291
```
281292

282-
Use `git diff` to see the file changes, and `git add;git commit` to save them.
293+
Use `git diff` to see the file changes.
283294
The next time tests are run using `--short` all the slow tests will be skipped.
284295

296+
[testjson]: https://golang.org/cmd/test2json/
297+
285298

286299
### Run tests when a file is modified
287300

0 commit comments

Comments
 (0)