Go testing overview
In this section, we are going to provide a high-level overview of Go’s testing capabilities. We will cover the basics of writing tests for Go code, list the useful functions and libraries provided with the Go SDK, and describe various techniques for writing tests that will help you in microservice development.
First, let’s cover the basics of writing tests for Go applications.
Go language has built-in support for writing automated tests and provides a package called testing
for this purpose.
There is a conventional relationship between the Go code and its tests. If you have a file called example.go
, its tests would reside in the same package in a file called example_test.go
. Using a _test
file name suffix allows you to differentiate between the code being tested and the tests for it, making it easier to navigate the source code.
Go test functions follow this conventional name format, with each test function name starting with the Test
prefix...