Skip to content

Instantly share code, notes, and snippets.

@dmotylev
Last active June 20, 2018 10:47
Show Gist options
  • Save dmotylev/3e1fa955fba45a9aa8c44e47296bf821 to your computer and use it in GitHub Desktop.
Save dmotylev/3e1fa955fba45a9aa8c44e47296bf821 to your computer and use it in GitHub Desktop.
Go's test func template
func TestType_TestFunc(t *testing.T) {
tests := []struct {
name string
wantErr bool
}{
{"test", false},
}
const wantTest = -1
for testNo, test := range tests {
//noinspection GoBoolExpressions
if wantTest > -1 && wantTest != testNo {
continue
}
t.Run(fmt.Sprintf("%d_%s", testNo, test.name), func(t *testing.T) {
var err error
// err := TestFunc()
if test.wantErr != (err != nil) {
t.Errorf("TestFunc() err=%v, wantErr=%t", err, test.wantErr)
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment