O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

The testing package of the standard library provides support for the code testing needs. The test function needs to fulfill the name pattern, TestXXX. By default, the test tool looks for the file named xxx_test.go. Note that each test function takes the T pointer argument, which provides the useful methods for test control. By the T struct pointer, the status of the test could be set. For instance, the methods Fail and FailNow, cause the test to fail. With the help of the T struct pointer, the test could be skipped by calling SkipSkipf, or SkipNow.

The interesting method of the T pointer is the method Helper. By calling the method Helper, the current function is marked as the helper function, and if the FailNow (Fatal) is ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required