Member-only story

Neovim for Minimalists — Test-Driven Development

Minimalist approach for test-driven development.

--

Neovim for Minimalists — Test-Driven Development

In this article, we will use Neovim Lua APIs to automate the unit testing process, without using any plugins.

This article is part of the Neovim for Minimalists series.

The Neovim configuration files are available in this repository.

Getting Started

In the beginner series, we use vim-test, Neotest, nvim-dap, and overseer.nvim to automate the testing and debugging process.

For those who are not familiar with Lua, you can go through these articles to set up test-driven development workflow in Neovim.

Using the Neovim Tree-sitter and Lua APIs, we can easily set up a test-driven development workflow, without any plugins.

We will use Python and the built-in unittest framework as an example to develop the testing workflow, as shown below.

PyTestAll

Using the :PyTestAll command, we can unit test all the test scenarios.

PyTestAll
  • For those successful test cases, we use the nvim_buf_set_extmark API to mark them as success.
  • For those failed test cases, we use the vim.diagnostic.set API to show the error message.

PyTestNearest

Using the :PyTestNearest command, we can unit test the nearest test scenario.

PyTestNearest

In the screenshot above, we use the cursor position to determine the nearest test case.

PyTestLast

Using the :PyTestLast command, we can re-test the last test scenario.

--

--

alpha2phi
alpha2phi

Written by alpha2phi

Software engineer, Data Science and ML practitioner.

No responses yet