Last active
April 27, 2020 22:06
-
-
Save negz/e6223997a85273ccbc8bf08b5c9df12a to your computer and use it in GitHub Desktop.
Common setup code in Go tests
This file contains hidden or 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
func TestDoTheThing(t *testing.T) { | |
cases := map[string]struct{ | |
thingArg string | |
want bool | |
}{ | |
// Add test cases here. | |
} | |
SetupTheThing() | |
for name, tc := range cases { | |
t.Run(name, func(t *testing.T) { | |
got := DoTheThing(tc.thingArg) | |
if diff := cmp.Diff(tc.want, got); diff != "" { | |
t.Errorf("Test failed: %s", diff) | |
} | |
} | |
} | |
TeardownTheThing() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment