Re:Google’s Go Style Guide
by Beltalowda on Friday November 18, 2022 @02:00PM
(#33660156)
The main reason I dislike the assert libraries is that you lose the ability to format things nicely; being able to see what's going on quickly is pretty nice when tests fail. Sometimes you want %s, sometimes %q, sometimes maybe a diff or formatted as something else. Testify "solves" this by just dumping a lot of stuff to your terminal, which is a crude brute-force solution. Plus with table-driven test you're saving what, 2 or 3 lines of code?
For example for a simple string comparison it's 12 lines:
For example for a simple string comparison it's 12 lines:
vs. 2 lines with a "normal" test: With your NotNil() example it's 4 lines, which seems about 3 lines more than needed.This kind of stuff really adds up if you have maybe 3 or 4 test failures.