Testing your Golang code
When I start a new project I begin by working on the interfaces like command line, services, plugins, etc. (the APIs). Once my API draft is good enough, I started writing tests. And I had to find out recently that Testing in Golang takes a little bit more attention than usual. Workarounds for bad design like mocking and monkey-patching are not readily available in Go like they are in dynamic languages. Many testing remedies are already available in Golang that promise to ease the pain but the general advice is not to use them. Instead one should make ones code testable and use the standard testing tools that are shipped with Golang itself. As always tools are a matter of taste and personal preferences - I wanted to do it in the recommended way.
(read more …)