Testing
The eBay MCP Server maintains high code quality through comprehensive testing with 870+ tests achieving 99%+ function coverage and 85%+ line coverage. This guide explains the testing strategy, tools, and how to write effective tests.Testing Overview
Test Statistics
Total Tests
870+ testsComprehensive test suite
Function Coverage
99%+ coverageNearly all functions tested
Line Coverage
85%+ coverageHigh code coverage
Testing Philosophy
- Test Behavior, Not Implementation - Tests should verify outcomes, not internal details
- Fast Feedback - Tests should run quickly to enable rapid development
- Isolated Tests - Each test should be independent and not rely on others
- Clear Assertions - Test failures should clearly indicate what went wrong
- Realistic Scenarios - Tests should reflect real-world usage patterns
Test Framework
The project uses Vitest as the test framework, chosen for its:- Native TypeScript support
- Fast execution with parallel testing
- Jest-compatible API
- Built-in coverage reporting
- Watch mode for development
Configuration
The test configuration is defined invitest.config.ts:
Test Structure
Directory Organization
Test Types
1. Unit Tests
Unit tests verify individual functions and classes in isolation. Example: Testing the OAuth client2. Integration Tests
Integration tests verify that components work together correctly. Example: Testing inventory API integration3. MCP Server Tests
End-to-end tests verify the entire MCP server functionality.Running Tests
Basic Commands
Watch Mode
Watch mode automatically re-runs tests when files change:- Automatic test re-execution on file changes
- Filter tests by filename or pattern
- Run only failed tests
- Interactive menu for test control
Coverage Reporting
Generate detailed coverage reports:coverage/index.html- Interactive HTML reportcoverage/lcov.info- LCOV format for CI toolscoverage/coverage-final.json- JSON format
Test UI Dashboard
Launch an interactive test dashboard:- Visual test runner
- Real-time test execution
- Coverage visualization
- Test file browser
- Interactive filtering
Writing Tests
Test Naming Conventions
- Use
describefor grouping related tests - Use
itfor individual test cases - Start test descriptions with “should”
- Be specific about what is being tested
- Include the condition or scenario
Test Structure (AAA Pattern)
Follow the Arrange-Act-Assert pattern:Mocking
Mocking External Dependencies
Mocking Time
Mocking Environment Variables
Testing Async Code
Testing Error Handling
Testing Best Practices
1. Test One Thing
Each test should verify one specific behavior
2. Use Descriptive Names
Test names should clearly describe what is being tested
3. Avoid Test Interdependence
Tests should not depend on each other
4. Keep Tests Simple
Tests should be easy to read and understand
5. Use Test Fixtures
Reuse common test data through fixtures
Coverage Requirements
Thresholds
The project enforces minimum coverage thresholds:Excluded Files
Some files are excluded from coverage:- Type definitions (
**/*.d.ts) - Configuration files (
**/*.config.*) - Build output (
build/,dist/) - Test files (
tests/**) - Schema definitions (
src/utils/**) - Server entry points (
src/index.ts,src/server-http.ts)
Viewing Coverage
Continuous Integration
Tests run automatically on every commit via GitHub Actions.CI Workflow
Debugging Tests
Enable Debug Output
Using Debugger
VSCode Debugging
.vscode/launch.json:
Related Topics
Contributing
Contribution guidelines and setup
Architecture
Understand the system architecture
Error Handling
Error handling strategies
GitHub Repository
View the source code and tests