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 to do it...

  1. Open the console and create the folder chapter11/recipe02.
  2. Navigate to the directory.
  3. 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, t *testing.T) {          t.Helper()          if expected != result {            t.Fatalf("Expected result %v does not match result %v",                     expected, result)          }        } func compare(expected, ...

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