Files
nvim/docs/cheatsheets/testing.md
Morten Olsen b3b70bceeb Improved flow
2026-01-26 23:04:14 +01:00

2.7 KiB

Testing Cheatsheet

Quick Reference

Key Action
<leader>tt Run nearest test
<leader>tf Run file tests
<leader>ta Run all tests
<leader>td Debug test
<leader>ts Toggle summary

Running Tests

<leader>tt    Run nearest test (cursor position)
<leader>tf    Run all tests in current file
<leader>ta    Run all tests in project
<leader>tl    Re-run last test
<leader>tS    Stop running tests

Debugging Tests

<leader>td    Debug nearest test (with DAP)
<leader>tD    Debug all tests in file

Watch Mode

<leader>tw    Toggle watch mode (file)
<leader>tW    Toggle watch mode (nearest)

Tests auto-run when file changes.

Output & Results

<leader>ts    Toggle test summary panel
<leader>to    Show output for nearest test
<leader>tO    Toggle output panel

Navigation

]t            Jump to next failed test
[t            Jump to previous failed test

Test Summary Panel

When summary is open (<leader>ts):

<cr>          Jump to test
o             Show output
i             Show short output
O             Show full output
m             Mark test
M             Clear marks
r             Run marked/nearest
R             Run all in file
d             Debug test

Framework-Specific

Vitest (TypeScript)

Files detected: *.test.ts, *.spec.ts, *.test.tsx, *.spec.tsx

// Test file example
describe('MyComponent', () => {
  it('should render', () => {
    // cursor here, <leader>tt runs this test
  })
})

Pytest (Python)

Files detected: test_*.py, *_test.py

# Test file example
def test_something():
    # cursor here, <leader>tt runs this test
    pass

class TestMyClass:
    def test_method(self):
        pass

Go Test

Files detected: *_test.go

// Test file example
func TestSomething(t *testing.T) {
    // cursor here, <leader>tt runs this test
}

Common Workflows

TDD Workflow

  1. Write failing test
  2. <leader>tw - Enable watch mode
  3. Write implementation
  4. Test auto-runs on save
  5. <leader>tw - Disable when done

Debug Failing Test

  1. ]t - Jump to failed test
  2. <leader>to - View output
  3. Set breakpoint if needed (<leader>db)
  4. <leader>td - Debug test
  5. Step through with DAP controls

Run Specific Tests

  1. <leader>ts - Open summary
  2. m on tests to mark them
  3. r to run marked tests

Troubleshooting

Tests Not Found

  • Check file naming convention
  • Verify neotest adapter is installed
  • Run :checkhealth neotest

Wrong Framework Used

  • Check testing.lua for adapter config
  • Ensure correct adapter is listed

Output Not Showing

  • <leader>tO to toggle output panel
  • Check if test actually ran