Run Tests in Parallel Using a Worktree
Execute long-running test suites or builds in one worktree while continuing development in another.
When to use
Your test suite takes several minutes to run, and you want to continue coding instead of waiting. A separate worktree lets you run tests in the background without blocking your workflow.
Pre-flight
- Commit or stash any changes you want to test (worktrees share the Git history but not uncommitted changes).
- Ensure you have enough system resources to run tests and your editor simultaneously.
Steps
-
Create a worktree for testing, pointing at the branch or commit you want to verify.
git worktree add ../test-runner mainOr test your current feature branch:
git worktree add -b test-feat ../test-runner HEAD -
Open a new terminal and navigate to the test worktree.
cd ../test-runner -
Install dependencies if needed and run your test suite.
npm ci npm test -
Continue working in your main directory while tests run in the other terminal.
-
When finished, clean up the test worktree.
cd ../your-main-repo git worktree remove ../test-runner
Verification
- Tests complete in the separate terminal without interrupting your main workflow.
git worktree listconfirms the test worktree is removed after cleanup.
Pro tip: Persistent test worktree
Keep a dedicated test worktree around for frequent use:
# Create once
git worktree add ../project-tests main
# Update to latest before each test run
cd ../project-tests
git checkout main
git pull origin main
npm test
Follow-up
- Consider setting up a CI pipeline if you find yourself doing this frequently.
- Use
tmuxor terminal splits to monitor test output while coding.