Skip to content

Instantly share code, notes, and snippets.

@mattmc3
Last active April 14, 2017 17:07
Show Gist options
  • Save mattmc3/6c6cd13bb96c0e7a20ca285ad7762ee8 to your computer and use it in GitHub Desktop.
Save mattmc3/6c6cd13bb96c0e7a20ca285ad7762ee8 to your computer and use it in GitHub Desktop.
Go: unittest file template
package main
import (
"reflect"
"testing"
)
func TestMath(t *testing.T) {
var tests = []struct {
input []int
expected int
}{
{[]int{2, 2}, 4},
{[]int{1, 2, 3}, 6},
}
for _, tt := range tests {
actual := 0
for _, item := range tt.input {
actual += item
}
if !reflect.DeepEqual(actual, tt.expected) {
t.Errorf(`Sum(%#v) == %#v; want %#v`, tt.input, actual, tt.expected)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment