Skip to main content

Testing Guide

Qwen Code uses a comprehensive testing strategy with unit tests, integration tests, and benchmarks to ensure code quality and reliability.

Overview

The project includes:
  • Unit Tests: Fast, isolated tests for individual components
  • Integration Tests: End-to-end tests validating complete workflows
  • Benchmarks: Performance tests for terminal operations
  • Sandbox Matrix: Tests across different sandboxing configurations

Test Framework

Vitest

All tests use Vitest as the test runner:

Configuration

Test configuration in vitest.config.ts:

Unit Tests

Running Unit Tests

Test File Location

Unit tests are co-located with source files:

Writing Unit Tests

Basic Test Structure:

Mocking

File System Mocking

Use memfs or mock-fs for file system operations:

HTTP Mocking

Use msw for HTTP request mocking:

Function Mocking

Use Vitest’s built-in mocking:

Test Utilities

Shared utilities in packages/test-utils:

Integration Tests

Overview

Integration tests validate end-to-end functionality by:
  • Building the project
  • Running the CLI binary
  • Executing real workflows
  • Verifying file system changes

Running Integration Tests

Running Specific Tests

Test Structure

Integration tests are in the integration-tests/ directory:

Writing Integration Tests

Sandbox Matrix Testing

Tests run across different sandbox configurations:
  • None: No sandboxing (fastest)
  • Docker: Docker-based sandbox
  • Podman: Podman-based sandbox
This ensures compatibility across all environments.

Benchmarks

Terminal Benchmarks

Performance tests for terminal operations:

Writing Benchmarks

CI/CD Testing

Preflight Checks

Before submitting a PR, run the full check:
This runs:
  1. Clean build artifacts
  2. Fresh npm ci install
  3. Code formatting check
  4. Linting (zero warnings)
  5. Full build
  6. Type checking
  7. All unit tests
  8. Script tests

CI Pipeline

GitHub Actions runs:

Test Coverage

Generating Coverage Reports

Coverage Goals

  • Overall: >80% coverage
  • Critical paths: >90% coverage
  • New features: 100% coverage required

Testing Best Practices

General Guidelines

  1. Fast Tests: Unit tests should run in milliseconds
  2. Isolated: Tests should not depend on each other
  3. Deterministic: Same input = same output
  4. Clear Names: Describe what is being tested
  5. Single Assertion: One concept per test

Naming Conventions

Test Organization

Async Testing

Error Testing

Debugging Tests

Running Single Tests

Debug Output

VS Code Debugging

Add to .vscode/launch.json:

Troubleshooting

Common Issues

Tests Timeout:
Flaky Tests:
File System Issues:

Next Steps