vim / run tests

I run tests from Vim without switching to a shell, keeping the test-driven feedback loop tight.

The vim-test plugin exposes :TestNearest, :TestFile, and :TestLast, which I bind to <Leader>s, <Leader>t, and <Leader>l:

map("n", "<Leader>s", ":TestNearest<CR>")
map("n", "<Leader>t", ":TestFile<CR>")
map("n", "<Leader>l", ":TestLast<CR>")

Nearest

With the cursor inside a test, <Leader>s runs only that one:

go test -run TestWorkOnce ./jobs
ok      eds/jobs        0.012s

vim-test detects the framework from the file and runs the command in a shell split.

File

<Leader>t runs the whole file's package to confirm the rest still passes:

go test ./jobs
ok      eds/jobs        0.108s

Last

<Leader>l re-runs the last command from anywhere, so I can edit the implementation and re-test without navigating back to the test.

The three bindings cover the red-green-refactor loop and cut the switching cost between editor and shell.

← All articles