You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
funcTestFoo(t*testing.T) {
testTable:= []struct {
testNamestringexpectedErrerror// add more variables to the test case here
} {
{
testName: "it should foo bar baz",
expectedErr: errors.New("foo"),
},
}
for_, testCase:=rangetestTable {
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.
The text was updated successfully, but these errors were encountered:
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.
Notice that test tables don't completely replace normal test cases. There are moments we simply should not use test tables.
The text was updated successfully, but these errors were encountered: