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.
In the beginner series, we use
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.
- Neovim for Beginners — Testing
- Neovim for Beginners — Testing (Part 2)
- Neovim For Beginners — Test Debugging and Automation
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 command, we can unit test all the test scenarios.
- For those successful test cases, we use the
nvim_buf_set_extmarkAPI to mark them as success.
- For those failed test cases, we use the
vim.diagnostic.setAPI to show the error message.
:PyTestNearest command, we can unit test the nearest test scenario.
In the screenshot above, we use the cursor position to determine the nearest test case.
:PyTestLast command, we can re-test the last test scenario.