Testing Extensions
Visual Studio Code supports running and debugging tests for your extension. These tests will run inside a special instance of VS Code named the Extension Development Host, and have full access to the VS Code API. We refer to these tests as integration tests, because they go beyond unit tests that can run without a VS Code instance. This documentation focuses on VS Code integration tests.
Overview
If you are using the Yeoman Generator to scaffold an extension, integration tests are already created for you.
In the generated extension, you can use npm run test
or yarn test
to run the integration tests that:
- Downloads and unzips latest version of VS Code.
- Runs the Mocha tests specified by the extension test runner script.
Quick Setup: The test CLI
The VS Code team publishes a command-line tool to run extension tests. You can find an example in the extensions sample repo.
The test CLI provides quick setup, and also allows you to easily run and debug tests of the VS Code UI using the Extension Test Runner. The CLI exclusively uses Mocha under the hood.
To get started, you'll want to first install the @vscode/test-cli
module, as well as @vscode/test-electron
module that enables tests to be run in VS Code Desktop:
npm install --save-dev @vscode/test-cli @vscode/test-electron