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/recipe04.
  2. Navigate to the directory.
  3. Create the file sample_test.go with the following content:
        package main        import (          "fmt"          "strconv"          "testing"        )        var testData = []int{10, 11, 017}        func TestSampleOne(t *testing.T) {          expected := "10"          for _, val := range testData {            tc := val            t.Run(fmt.Sprintf("input = %d", tc), func(t *testing.T) {              if expected != strconv.Itoa(tc) {                t.Fail()              }            })          }        }
  1. Execute the tests by go test -v.
  2. See the output in the Terminal:

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