Created
November 22, 2016 17:15
-
-
Save kare/8e847c5d349ebe1df74b1a99ba3eff4b to your computer and use it in GitHub Desktop.
Go unit test setup and teardown math_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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