Skip to content

Instantly share code, notes, and snippets.

@bwplotka
Created January 7, 2019 14:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bwplotka/a151fe43c9851ef092d29f912e7f8ca7 to your computer and use it in GitHub Desktop.
Save bwplotka/a151fe43c9851ef092d29f912e7f8ca7 to your computer and use it in GitHub Desktop.
Table test initial boilerplate
for _, tcase := range []struct{
}{
{
},
}{
if ok := t.Run("", func(t *testing.T) {
}); !ok {
return
}
}
@bwplotka
Copy link
Author

bwplotka commented Jan 7, 2019

Useful codegen configuration for Goland:

Double shift -> "live templates" -> Go -> + -> paste this code into template text

@metalmatze
Copy link

Thanks for sharing. I've added this to GoLand with a few changes.

testcases := []struct {
	Name string
}{
	{
		Name: "foo",
	},
	{
		Name: "bar",
	},
	{
		Name: "baz",
	},
	{
		Name: "foo",
	},
}

for _, tc := range testcases {
	tc := tc
	t.Run(tc.Name, func(t *testing.T) {
		t.Parallel()
		if tc.Name != "foo" {
			t.Errorf("foo is expected test name: got %v", tc.Name)
		}
	})
}```

@quii
Copy link

quii commented Jan 17, 2019

Thanks both, this is great!

I've iterated on it a bit

testcases := []struct {
	Name string
}{
	{
		Name: "$NAME$",
	},
}

for _, tc := range testcases {
	tc := tc
	t.Run(tc.Name, func(t *testing.T) {
		t.Parallel()
		$END$
	})
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment