October 2015
Beginner to intermediate
400 pages
14h 44m
English
Test Functions
Each test file must import the testing package.
Test functions have the following signature:
func TestName(t *testing.T) {
// ...
}
Test function names must begin with Test;
the optional suffix Name must begin with
a capital letter:
func TestSin(t *testing.T) { /* ... */ }
func TestCos(t *testing.T) { /* ... */ }
func TestLog(t *testing.T) { /* ... */ }
The t parameter provides methods for reporting test failures and
logging additional information. Let’s define an example package
gopl.io/ch11/word1, containing a single function IsPalindrome that reports whether a string reads the same forward and backward. (This implementation tests every byte twice if the string is a palindrome; we’ll come ...