Overview
VS Code has a comprehensive test suite covering unit tests, integration tests, extension tests, and smoke tests. Understanding how to run and write tests is essential for contributing to VS Code.Unit Tests
Test individual components in isolation
Integration Tests
Test interactions between components
Extension Tests
Test built-in extension functionality
Test Infrastructure
Test Locations
- Unit Tests
- Integration Tests
- Extension Tests
Unit tests are located alongside source files:Test Files:
*.test.ts in test/ subdirectoriesEntry Point: test/unit/electron/index.jsRunning Unit Tests
Command Line
- Linux/macOS
- Windows
- npm scripts
Run all unit tests:Run specific test file:Filter tests by name:Run with debugger:
Environment Setup
The test script automatically:- Checks for
node_modulesand runsnpm iif needed - Downloads Electron (unless
VSCODE_SKIP_PRELAUNCH=1) - Runs tests with Electron binary
- Saves crash reports to
.build/crashes
Tests run in Electron to test both Node.js and browser APIs in the same environment as VS Code.
Running Integration Tests
Full Integration Test Suite
- Linux/macOS
- Windows
- Individual Suites
- Node.js integration tests (
**/*.integrationTest.js) - Extension API tests (folder and workspace)
- Colorize tests
- Terminal suggest tests
- Language feature tests (TypeScript, Markdown, etc.)
- Git tests
- Standalone tests (CSS, HTML)
Test Configuration
Integration tests use special arguments:Extension Tests
Using @vscode/test-cli
The repository uses@vscode/test-cli for running extension tests, configured in .vscode-test.js:
Running Extension Tests
Available Extension Tests
- API Tests
- Language Features
- Other Extensions
Test the VS Code Extension API:Test Location:
extensions/vscode-api-tests/out/Coverage: Commands, languages, workspace, debug API, etc.Web Tests
Test VS Code in browser environments:Debugging Tests
VS Code Launch Configurations
Use the pre-configured debug configurations:- All Unit Tests
- Current File
- Extension Tests
Configuration:
Debug Unit Tests- Open Run and Debug view (
Cmd/Ctrl + Shift + D) - Select “Debug Unit Tests”
- Press
F5
Command Line Debugging
Writing Tests
Unit Test Structure
VS Code uses Mocha with a TDD-style interface:Test Organization
1
Use suite() for grouping
2
Use test() for individual tests
3
Use setup() and teardown()
Best Practices
Minimize Assertions
Minimize Assertions
Prefer one comprehensive assertion over multiple precise ones:
This makes tests easier to understand and update when requirements change.
Add to Correct Suite
Add to Correct Suite
Always add tests to existing suites instead of creating new files:Don’t create a new test file unless testing a new component.
Use Async/Await
Use Async/Await
For asynchronous tests:
Test Error Cases
Test Error Cases
Don’t just test the happy path:
Clean Up Resources
Clean Up Resources
Always dispose of resources:
Integration Test Example
Integration tests use the full VS Code API:Smoke Tests
Smoke tests verify basic functionality in a real environment:test/smoke/
Coverage: File operations, editor features, extensions, settings, etc.
CI/CD Test Execution
Tests run automatically in CI/CD:- Core CI
- Extensions CI
- Unit tests
- Integration tests
- Code hygiene checks
- Layer validation
Troubleshooting
Tests Fail Locally but Pass in CI
Tests Fail Locally but Pass in CI
- Check Node.js version matches CI
- Ensure clean git state:
git clean -xfd - Rebuild:
npm run compile - Check for OS-specific issues
Tests Time Out
Tests Time Out
- Increase timeout in test:
- Check for deadlocks or infinite loops
- Run with
--inspect-brkto debug
Extension Tests Fail
Extension Tests Fail
- Ensure extension is compiled:
npm run watch-extensions - Check workspace folder exists
- Verify extension activation events
- Check logs in
.build/logs/integration-tests
Cannot Find Module Errors
Cannot Find Module Errors
- Run
npm install - Clear cache:
rm -rf out node_modules/.cache - Recompile:
npm run compile
Next Steps
Debugging
Learn how to debug tests
Development Workflow
Understand the development process
Building from Source
Review build instructions
Mocha Documentation
Learn more about Mocha testing framework