Test
Testify
go get -u github.com/stretchr/testify
package somepackage_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"somepackage"
)
Table Driven Tests
func TestAddOne(t *testing.T) {
cases := []struct {
in int
want int
}{
{1, 2},
{2, 3},
{3, 4},
}
for _, c := range cases {
got := c.in + 1
assert.Equal(t, got, c.want)
}
}
Setup and Teardown
func TestMain(m *testing.M) {
// setup
code := m.Run()
// teardown
os.Exit(code)
}