Testing the code
Testing and benchmarking naturally belong to software development. Go, as a modern language with its built-in libraries, supports these from scratch. In this recipe, the basics of testing will be described.
How to do it...
- Open the console and create the folder
chapter11/recipe02
. - Navigate to the directory.
- Create the file
sample_test.go
with the following content:
package main import ( "strconv" "testing" ) func TestSampleOne(t *testing.T) { expected := "11" result := strconv.Itoa(10) compare(expected, result, t) } func TestSampleTwo(t *testing.T) { expected := "11" result := strconv.Itoa(10) compareWithHelper(expected, result, t) } func TestSampleThree(t *testing.T) { expected := "10" result := strconv.Itoa(10) compare(expected, result, t) } func compareWithHelper(expected, result string...