Skip to content

Instantly share code, notes, and snippets.

@kare
Created November 22, 2016 17:15
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 kare/8e847c5d349ebe1df74b1a99ba3eff4b to your computer and use it in GitHub Desktop.
Save kare/8e847c5d349ebe1df74b1a99ba3eff4b to your computer and use it in GitHub Desktop.
Go unit test setup and teardown math_test.go
package math
import "testing"
func TestAddition(t *testing.T) {
cases := []struct {
name string
a int
b int
expected int
}{
{"add", 2, 2, 4},
{"minus", 0, -2, -2},
{"zero", 0, 0, 0},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
result := Sum(tc.a, tc.b)
if result != tc.expected {
t.Fatalf("expected sum %v, but got %v", tc.expected, result)
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment