In some cases, it is useful to create a set of tests that could have a similar setup or clean-up code. This could be done without having a separate function for each test.
Creating subtests
How to do it...
- Open the console and create the folder chapter11/recipe04.
- Navigate to the directory.
- 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...