How do I run tests from inside Vim?
Answer
:TestNearest (vim-test)
Explanation
vim-test provides commands to run tests from within Vim. It detects the test framework and runs the appropriate test commands.
How it works
:TestNearestruns the test nearest to the cursor:TestFileruns all tests in the current file:TestSuiteruns the entire test suite:TestLastre-runs the last test
Example
nmap <leader>t :TestNearest<CR>
nmap <leader>T :TestFile<CR>
nmap <leader>a :TestSuite<CR>
nmap <leader>l :TestLast<CR>
Tips
- Install:
Plug 'vim-test/vim-test' - Supports many frameworks: pytest, jest, go test, rspec, etc.
let test#strategy = 'neovim'runs tests in a Neovim terminal:TestVisitopens the last test file- Configure custom test commands per project