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 β€” and Xxx does 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 BenchmarkXxx and should have the signature:
func BenchmarkXxx(b *testing.B) { ...  }
  • a fuzz test is one named FuzzXxx and 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