Skip to main content

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

  1. Test Behavior, Not Implementation - Tests should verify outcomes, not internal details
  2. Fast Feedback - Tests should run quickly to enable rapid development
  3. Isolated Tests - Each test should be independent and not rely on others
  4. Clear Assertions - Test failures should clearly indicate what went wrong
  5. 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 in vitest.config.ts:

Test Structure

Directory Organization

Test Types

1. Unit Tests

Unit tests verify individual functions and classes in isolation. Example: Testing the OAuth client

2. Integration Tests

Integration tests verify that components work together correctly. Example: Testing inventory API integration

3. 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:
Features:
  • 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:
Output:
Coverage Files:
  • coverage/index.html - Interactive HTML report
  • coverage/lcov.info - LCOV format for CI tools
  • coverage/coverage-final.json - JSON format

Test UI Dashboard

Launch an interactive test dashboard:
Features:
  • Visual test runner
  • Real-time test execution
  • Coverage visualization
  • Test file browser
  • Interactive filtering

Writing Tests

Test Naming Conventions

Guidelines:
  • Use describe for grouping related tests
  • Use it for 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

Run with debugger:

VSCode Debugging

.vscode/launch.json:

Contributing

Contribution guidelines and setup

Architecture

Understand the system architecture

Error Handling

Error handling strategies

GitHub Repository

View the source code and tests