|
|
|
|
|
by dgunay
1304 days ago
|
|
Drawing inspiration from: > Complex assertion functions often do not provide useful failure messages and context that exists within the test function. I think the best compromise is to avoid combining individual logical units into one assertion. For example: Bad: assert.True(t, myStr == "expected" && myInt == 5)
Good: assert.Equal(t, "expected", myStr)
assert.Equal(t, 5, myInt)
Real world example: at my workplace we have some code that tests HTTP request formation for correctness (right URL, body, headers, etc). Replacing big all-or-nothing booleans with individual assertions on each property of the request provides much more useful test failure messages.As with any published "best practices" like this, have an open mind but don't just cargo cult whatever Google does. Best to be selective about what does and doesn't work for your situation. |
|