You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current testing package documentation states:
"These TestXxx routines should be declared within the package they are
testing."
There's no mention of the commonly used technique of creating a file with
package foo_test
instead of
package foo
for blackbox or example purposes.
The text was updated successfully, but these errors were encountered:
I'm willing to, but I'm not sure about the specifics of how the mechanism works.
Does the package name need to end in _test? It seems so, since otherwise go build and go
test complain about multiple packages in the directory.
Any other subtleties I should be aware of?
> Does the package name need to end in _test? It seems so, since otherwise go build and
go test complain about multiple packages in the directory.
Yes. It's actually codified in cmd/go/test.go +420, and doc.go +343. These fields are
can be inspected by go list,
lucky(~) % go list -f '{{ .TestGoFiles }}' bytes
[export_test.go]
lucky(~) % go list -f '{{ .XTestGoFiles }}' bytes
[buffer_test.go bytes_test.go example_test.go reader_test.go]
But you are correct that package $PKG_test is special.
> Any other subtleties I should be aware of?
Watch out for the duplication test.go has a description of the command which is part of
the go help output, but doc.go has the godoc string, those two need to be kept in sync.
See mkdoc.sh in that directory, plus this comment in doc.go:
// DO NOT EDIT THIS FILE. GENERATED BY mkdoc.sh.
// Edit the documentation in other files and rerun mkdoc.sh to generate this one.
The text was updated successfully, but these errors were encountered: