# Writing testable examples in Go

DevFeed: [Writing testable examples in Go](<https://devfeed.tech/articles/writing-testable-examples-in-go-22211.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2023/01/writing-testable-examples-in-go.html>)

Published: 2023-01-12T00:00:00Z

Content type: tutorial

Language: en

Sources: [William Kennedy](<https://devfeed.tech/sources/william-kennedy.md>)

Topics: [Go Language](<https://devfeed.tech/topics/go-language.md>), [code comments](<https://devfeed.tech/topics/code-comments.md>)

Tags: [api](<https://devfeed.tech/tags/api.md>), [code-comments](<https://devfeed.tech/tags/code-comments.md>), [documentation](<https://devfeed.tech/tags/documentation.md>), [formatting](<https://devfeed.tech/tags/formatting.md>), [generate-documentation](<https://devfeed.tech/tags/generate-documentation.md>), [go](<https://devfeed.tech/tags/go.md>), [golang](<https://devfeed.tech/tags/golang.md>), [run](<https://devfeed.tech/tags/run.md>), [test](<https://devfeed.tech/tags/test.md>), [testable-examples](<https://devfeed.tech/tags/testable-examples.md>)

## AI overview

Go documentation can include runnable examples that users can paste into a scratch file to try a package or API. The video describes adding a source file to a package, defining a test function, and writing the comments and syntax Go uses to display and format testable code in generated documentation. Documentation can be viewed in the terminal or, for publicly accessible code, on pkg.go.dev.

## Source excerpt

Introduction Google developed Go to be an alternative to C++ with the internet and scale in mind. Go's toolchain automates tasks that are easily overlooked, and amongst those tasks is generating documentation. Go has the ability to generate documentation based on comments written in your source code. As the end user, you have the choice to view this documentation in your terminal or, if your code is publicly accessible, on pkg.go.dev. Go also offers special comment syntax to further format and style the generated documentation.