Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.