Skip to content

Instantly share code, notes, and snippets.

@mattmc3
Last active April 14, 2017 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattmc3/eb39dfb9a59f1222c154e80311dcdaa4 to your computer and use it in GitHub Desktop.
Save mattmc3/eb39dfb9a59f1222c154e80311dcdaa4 to your computer and use it in GitHub Desktop.
Go: unittest method template
func Test{{THING}}(t *testing.T) {
var tests = []struct {
input string
expected string
}{
{``, ``},
}
for _, tt := range tests {
method := fmt.Sprintf(`{{THING}}(%#v)`, tt.input)
actual, err := {{THING}}(tt.input)
if err != nil {
t.Errorf(`%v errored unexpectedly: %#v`, method, err.Error())
} else if !reflect.DeepEqual(actual, tt.expected) {
t.Errorf(`%v == %#v; want %#v`, method, actual, tt.expected)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment