浏览 174
分享
Test Tables
Use table-driven tests with subtests to avoid duplicating code when the coretest logic is repetitive.
Bad | Good |
---|---|
|
|
Test tables make it easier to add context to error messages, reduce duplicatelogic, and add new test cases.
We follow the convention that the slice of structs is referred to as tests
and each test case tt
. Further, we encourage explicating the input and outputvalues for each test case with give
and want
prefixes.
- tests := []struct{
- give string
- wantHost string
- wantPort string
- }{
- // ...
- }
- for _, tt := range tests {
- // ...
- }
评论列表