GO-TESTFUNC(7)
β¨ GO-TESTFUNC(7) β testfunc, a.k.a. testing functions β¨
okay so bestie, welcome to the testfunc manual page π it lives in the Go programming tools and commands section of the manual, so you already know it's giving main character energy. grab a boba, we're learning how Go finds your tests π
π NAME π
testfunc β testing functions. that's it, that's the name, iconic π
πΈ DESCRIPTION πΈ
so the go test command is out here looking for test, benchmark, and example functions inside the β*_test.goβ files that correspond to the package you're testing. yes, the naming matters, she's picky like that π
π§ͺ the function lineup
- a test function is one named
TestXxxβ andXxxdoes not start with a lower case letter, okay? don't try it β and it should have the signature:
func TestXxx(t *testing.T) { ... }
- a benchmark function is one named
BenchmarkXxxand should have the signature:
func BenchmarkXxx(b *testing.B) { ... }
- a fuzz test is one named
FuzzXxxand should have the signature:
func FuzzXxx(f *testing.F) { ... }
π¦ and now, examples (they're lowkey different)
an example function is similar to a test function but, instead of using *testing.T to report success or failure, it prints output to os.Stdout. think of it as the test's artsy cousin π¨
here's the tea on the trailing comments:
- if the last comment in the function starts with
βOutput:βthen the output is compared exactly against the comment (examples below, bestie, keep scrolling π) - if the last comment begins with
βUnordered output:βthen the output is compared to the comment, however the order of the lines is ignored. so chaotic, so free π - an example with no such comment is compiled but not executed. it's just there for the vibes π§
- an example with no text after
βOutput:βis compiled, executed, and expected to produce no output. silence, but make it intentional π€«
π godoc says hi
Godoc displays the body of ExampleXxx to demonstrate the use of the function, constant, or variable Xxx. so your examples are literally doing PR for your API, periodt π
an example of a method M with receiver type T or *T is named ExampleT_M. and yes, there may be multiple examples for a given function, constant, or variable, distinguished by a trailing _xxx, where xxx is a suffix not beginning with an upper case letter. lowercase suffix only, she said what she said π
β¨ here's an example of an example (yes, we're doing this)
func ExamplePrintln() {
Println("The output of\nthis example.")
// Output: The output of
// this example.
}
π and here's another one where the ordering of the output is ignored
func ExamplePerm() {
for _, value := range Perm(4) {
fmt.Println(value)
}
// Unordered output: 4
// 2
// 1
// 3
// 0
}
π one more rule, and it's a good one
the entire test file is presented as the example when it contains:
- a single example function,
- at least one other function, type, variable, or constant declaration,
- and no tests, benchmarks, or fuzz tests.
that's the whole vibe check right there β
fr fr, go read the documentation of the testing package for more information. this page is just the appetizer, bestie π«Ά
π AUTHOR π
this manual page was created using help2man and afterwards updating the output. it is maintained by the Debian Go Compiler Team <team+go-compiler@tracker.debian.org> for the Debian project (and may be used by others). shoutout to them, they ate π
and that's a wrap on go-testfunc(7), bestie β¨ this one's from Go 1.27, dated August 2026, and it came to you straight from the Go programming tools and commands corner of the manual. mwah, go write some tests, you've got this π
ππ¦
π¦ where this page comes from
- ubuntu stonking: golang-go 2:1.27~1 Β· Go
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms