New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing: mention the “_test” package idiom #25223

Open
bcmills opened this Issue May 2, 2018 · 3 comments

Comments

Projects
None yet
4 participants
@bcmills
Member

bcmills commented May 2, 2018

https://tip.golang.org/cmd/go/#hdr-Test_packages says:

Test files that declare a package with the suffix "_test" will be compiled as a separate package, and then linked and run with the main test binary.

However, https://tip.golang.org/pkg/testing/ omits that detail (emphasis mine):

To write a new test suite, create a file whose name ends _test.go that contains the TestXxx functions as described here. Put the file in the same package as the one being tested.

Tests in a separate _test package provide more realistic examples (and are better for catching awkward package names), so it's important that users be aware of that option. The testing package is an important entry point for users who are new to Go: its documentation should mention both package options or neither.

@bcmills bcmills added this to the Unplanned milestone May 2, 2018

@rillig

This comment has been minimized.

Contributor

rillig commented Oct 27, 2018

After programming in Go for three years, I learned about this feature in this Stack Overflow answer. If the one sentence mentioning white-box and black-box testing had been in the reference documentation or the Effective Go document, it would have helped me quite a bit.

@gopherbot

This comment has been minimized.

gopherbot commented Oct 28, 2018

Change https://golang.org/cl/145279 mentions this issue: testing: mention the "_test" package idiom

@hearot

This comment has been minimized.

Contributor

hearot commented Oct 28, 2018

At least, now it is a bit mentioned. I may expand its documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment