11.1 The go test
Tool
The go test
subcommand is a test driver for Go packages that are organized
according to certain conventions. In a package directory, files whose
names end with _test.go
are not part of the package ordinarily built
by go build
but are a part of it when built by go test
.
Within *_test.go
files, three kinds of functions are treated
specially: tests, benchmarks, and examples. A test function, which is a
function whose name begins with Test
, exercises some program logic
for correct behavior; go test
calls the test function and reports
the result, which is either
PASS
or FAIL
. A benchmark function has a name beginning with Benchmark
and
measures the performance of some operation; go test
reports the mean execution time ...
Get The Go Programming Language now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.