#development #golang #testing

In my previous post, I've outlined how I write tests.

Since I ended up writing a lot of code multiple times, I made my life slightly easier by creating two simple snippets for Visual Studio Code.

tcimp

You can use the tcimp snippet to quickly add the basic imports needed for writing a test.

It uses the testing and assert libaries.

Just type tcimp and you'll get the following snippet:

1import (
2    "testing"
3
4    "github.com/stretchr/testify/assert"
5
6    "github.com/<package>"
7)

tcimp snippet

tc

Typing tc sets up the basic structure for an empty test and results in:

 1func Test_<name>(t *testing.T) {
 2
 3    type test struct {
 4        name string
 5    }
 6
 7    var tests = []test{}
 8
 9    for _, tc := range tests {
10        t.Run(tc.name, func(t *testing.T) {
11        })
12    }
13
14}

tc snippet

You can get the snippets from here.