Parallel tests in Go

Go surprises me with how simple it makes things. Today, it was parallel testing. In other languages I’ve used, it may require third-party packages, require complicated syntax, or may just not be possible. In Go, it’s as simple as:

import "testing"

func TestMeow(t *testing.T) {
    t.Parallel()
    // test logic here
}

func TestRoar(t *testing.T) {
    t.Parallel()
    // test logic here
}

func TestBark(t *testing.T) {
    // test logic here
}

Tests marked with t.Parallel() will execute in parallel with other tests also marked with t.Parallel(). So the tests TestMeow() and TestRoar() will run in parallel, but TestBark() will not.

In case you want to run tests serially despite marking them parallel, you can set the test.parallel flag instead of commenting out each t.Parallel() call.

$ go test -test.parallel 1
 
23
Kudos
 
23
Kudos

Now read this

Vim-like cursor keys on a 60% keyboard

I’m using a 60% keyboard, which has 61 keys—the WASD VP3. It doesn’t have dedicated cursor keys, so I set up Fn + hjkl to act as cursor keys. The default mappings use Fn + ijkl as cursor keys. Fn + i: up Fn + k: down Fn + j: left Fn + l:... Continue →