January 2020
Intermediate to advanced
640 pages
16h 56m
English
With the release of Go 1.7, the built-in testing package gained support for running subtests. Subtests are nothing more than a hierarchy of test functions that are executed sequentially. This hierarchical structuring of the test code is akin to the notion of a test suite that you may have been exposed to in other programming languages.
So, how does it work? The testing.T type has been augmented with a new method called Run that has the following signature:
Run(description string, func(t *testing.T))
This new method provides a new mechanism for spawning subtests that will run in isolation while still retaining the ability to use the parent test function to perform any required setup and teardown steps.
As you might expect, since ...