2 ms·
It's pretty much the same as in other languages, so don't over think it. The main difference for you will be Go is compiled, so you have to think slightly diffe
by blaisio 9y ago
It's pretty much the same as in other languages, so don't over think it. The main difference for you will be Go is compiled, so you have to think slightly differently when writing tests.
Here are a few don'ts:
- don't take interfaces as arguments unless it really makes sense, even if it makes testing easier
- don't use one of the tiny test helper libraries that basically just writes if statements for you
- don't start writing tests until you've already figured out how to organize your logging and errors
One pattern I found helpful was to write an adapter that uses the testing.T.Print* functions as the destination for log.Print* statements in my regular code so that log messages aren't jumbled when running tests in parallel.