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 invitest.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
Usememfs or mock-fs for file system operations:
HTTP Mocking
Usemsw for HTTP request mocking:
Function Mocking
Use Vitest’s built-in mocking:Test Utilities
Shared utilities inpackages/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 theintegration-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
Benchmarks
Terminal Benchmarks
Performance tests for terminal operations:Writing Benchmarks
CI/CD Testing
Preflight Checks
Before submitting a PR, run the full check:- Clean build artifacts
- Fresh
npm ciinstall - Code formatting check
- Linting (zero warnings)
- Full build
- Type checking
- All unit tests
- 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
- Fast Tests: Unit tests should run in milliseconds
- Isolated: Tests should not depend on each other
- Deterministic: Same input = same output
- Clear Names: Describe what is being tested
- 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:Next Steps
- Development Setup - Set up your environment
- Tools System - Testing tools
- Contributing - Submit your changes
