...

/

Testing and Benchmarking in Go

Testing and Benchmarking in Go

This lesson shows how to test a program before running it and therefore how to save it from panicking beforehand.

We'll cover the following...

Testing with tool

Every new package should contain sufficient documentation and test code. We already used Go’s testing tool go test in Chapter 7. Here, we will elaborate on its use with some more examples.

A special package called testing provides support for automated testing, logging, and error reporting. It also contains some functionality for benchmarking functions.

Remark: for Windows, every time you see the folder pkg/linux_amd64, replace it with pkg/windows.

To unit-test a package, you write several tests that you can frequently run (after every update) to check the correctness of your code in small units. For that, we ...