
gotest-snippets is a VSCode extension that will make it a little easier to write tests in golang by generating the majority of the boiler plate needed for common tests.
Why?
After working in golang for several years I found myself writing the same boilerplate over and over. This was exacerbated when new patterns would emerge and I wanted to update older tests.
These snippets are the ones I’ve grown to use regularly.
How?
Step 1
Download the extension from the VSCode marketplace here.
Step 2
Type gotest in a *.go file and VSCode should
offer you the snippets to use.
What are the Snippets?
There are only a handful of snippets this extension
will add, all starting with the prefix gotest.
- gotest
- Generate a table driven test
- gotest-diff
- Generate a diff statement (i.e. a want/got check)
- gotest-diffopts
- Generate a diff statement with options. This is equivalent to
gotest-diffexcept it’ll set up the options array.
- Generate a diff statement with options. This is equivalent to
- gotest-main
- Generate a
TestMainfunction with aresetfunction you can use to reset all global variables between tests.
- Generate a
- gotest-errors
- Generate an error comparison.
- gotest-errinject
- Generate an error to inject into test cases (useful for consistency).
Found an Issue?
If you've found an issue, please report it here.
Want the Source Code?
This project is available on GitHub at github.com/gauntface/gotest-snippets.
Found an issue?
All my posts are available to edit on GitHub, any fix is greatly appreciated!