Search⌘ K
AI Features

Testing Go Code

Explore the fundamentals of testing Go code by writing automated test functions to verify production code correctness. Understand how to test for expected, unexpected, and edge case inputs using practical examples, including random data. This lesson enables you to confidently detect bugs and improve code reliability with effective Go testing practices.

The subject of this lesson is the testing of Go code by writing test functions. Software testing is a very large subject and cannot be covered in a single lesson of a chapter in a course. So, this lesson tries to present as much practical information as possible.

Go allows us to write tests for our Go code to detect bugs. However, software testing can only show the presence of one or more bugs, not the absence of bugs. This means that we can never be 100% sure that our code has no bugs!

Strictly speaking, this lesson is about automated testing, which involves writing extra code to verify whether the real code—that is, the production code—works as ...