Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test tables for unit testing #34

Open
GuilhermeMLS opened this issue Jun 20, 2022 · 0 comments
Open

Test tables for unit testing #34

GuilhermeMLS opened this issue Jun 20, 2022 · 0 comments

Comments

@GuilhermeMLS
Copy link
Contributor

Test tables are an elegant way of reducing the amount of duplicated code when unit testing. The template project could have some test table examples.

func TestFoo(t *testing.T) {
	testTable := []struct {
		testName string
		expectedErr error
		// add more variables to the test case here
	} {
		{
			testName: "it should foo bar baz",
			expectedErr: errors.New("foo"),
		},
	}
	for _, testCase := range testTable {
		t.Run(testCase.testName, func(t *testing.T) {
			// Arrange
			
			// Act
			
			// Assert
		})
	}
}

Notice that test tables don't completely replace normal test cases. There are moments we simply should not use test tables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant