Skip to main content
Version: Capstone Spring 2025 (Archived)

Unit Tests

Testing Library

  1. Go
  2. Jest
  3. VSCode Testing Suite

1. gotest

Testing library included with Golang

Key Features

  • TODO

Running the unit tests

To run the unit tests for the API:

Windows

TODO

Mac/Linux

2. Jest

Used for unit testing core functionalities within the Visual Studio Code extension.

Modules:

  • jest – The main testing framework that runs unit tests efficiently in a Node.js environment.
  • ts-jest – Integrates Jest with TypeScript, enabling seamless testing of TypeScript code.

Key features

  • Built-in mocking capabilities for API calls and dependencies.
  • Code coverage reports to monitor untested portions of the extension.
  • Asynchronous test support for handling Promises and async functions.

Why it was chosen

  • Simple and intuitive API, making unit testing easy to write and maintain.
  • Optimized for Node.js-based applications, aligning well with VS Code Extensions.
  • Good mocking features for testing interactions with VS Code’s API without running a full VS Code instance.
  • Fast execution compared to other testing frameworks, reducing development cycle time.

Running the unit tests

To run the Jest tests:

cd extension
npm install
npx jest [name of test file] # Run a specific test
npx jest --coverage # Run all tests with coverage report

Test Structure

  • Each feature's methods will be encapsulated in a dedicated test file. For example:
    • suggestions.test.ts – Contains all related tests for fetching, modifying, and handling suggestions.
  • Running a Specific Test File
npx jest suggestions.test.ts

3. VSCode Testing Suite

Modules:

  • @vscode/test-cli – Provides command-line tools for running VS Code extension tests.
  • @vscode/test-electron – Runs tests in an Electron environment, simulating VS Code’s runtime.

Key Features

  • Allows running integration tests in a real VS Code instance.
  • Supports launching VS Code in a headless mode for automated testing.
  • Provides API hooks to interact with the VS Code extension environment.

Why it was chosen

  • Preinstalled when creating VS Code extensions.
  • Enables thorough testing of UI interactions and command execution.

Running the unit tests

To run the VS Code extension tests:

cd extension
npm install
npm test