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:

import (
    "testing"

    "github.com/stretchr/testify/assert"

    "github.com/<package>"
)

tcimp snippet

tc

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

func Test_<name>(t *testing.T) {

    type test struct {
        name string
    }

    var tests = []test{}

    for _, tc := range tests {
        t.Run(tc.name, func(t *testing.T) {
        })
    }

}

tc snippet

You can get the snippets from here.