Skip to Content
Hands-On Software Engineering with Golang
book

Hands-On Software Engineering with Golang

by Achilleas Anagnostopoulos
January 2020
Intermediate to advanced
640 pages
16h 56m
English
Packt Publishing
Content preview from Hands-On Software Engineering with Golang

Subtests

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Hands-On Software Architecture with Golang

Hands-On Software Architecture with Golang

Jyotiswarup Raiturkar

Publisher Resources

ISBN: 9781838554491Supplemental Content