Skip to main content

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 are located alongside source files:
Test Files: *.test.ts in test/ subdirectoriesEntry Point: test/unit/electron/index.js

Running Unit Tests

Command Line

Run all unit tests:
Run specific test file:
Filter tests by name:
Run with debugger:

Environment Setup

The test script automatically:
  1. Checks for node_modules and runs npm i if needed
  2. Downloads Electron (unless VSCODE_SKIP_PRELAUNCH=1)
  3. Runs tests with Electron binary
  4. 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

This script runs:
  1. Node.js integration tests (**/*.integrationTest.js)
  2. Extension API tests (folder and workspace)
  3. Colorize tests
  4. Terminal suggest tests
  5. Language feature tests (TypeScript, Markdown, etc.)
  6. Git tests
  7. 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

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:
Configuration: Debug Unit Tests
  1. Open Run and Debug view (Cmd/Ctrl + Shift + D)
  2. Select “Debug Unit Tests”
  3. Press F5
This runs all unit tests with the debugger attached.

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

Prefer one comprehensive assertion over multiple precise ones:
This makes tests easier to understand and update when requirements change.
Always add tests to existing suites instead of creating new files:
Don’t create a new test file unless testing a new component.
For asynchronous tests:
Don’t just test the happy path:
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:
Smoke Test Location: test/smoke/ Coverage: File operations, editor features, extensions, settings, etc.

CI/CD Test Execution

Tests run automatically in CI/CD:
Runs:
  • Unit tests
  • Integration tests
  • Code hygiene checks
  • Layer validation

Troubleshooting

  • Check Node.js version matches CI
  • Ensure clean git state: git clean -xfd
  • Rebuild: npm run compile
  • Check for OS-specific issues
  • Increase timeout in test:
  • Check for deadlocks or infinite loops
  • Run with --inspect-brk to debug
  • Ensure extension is compiled: npm run watch-extensions
  • Check workspace folder exists
  • Verify extension activation events
  • Check logs in .build/logs/integration-tests
  • 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