# Testing Strategy

## Overview

This document outlines the testing strategy for the Mahavishnu platform, covering unit, integration, and end-to-end tests.

## Test Categories

### Unit Tests

- Test individual functions and classes in isolation
- Fast execution (< 100ms per test)
- High coverage (95%+ for critical paths)
- Located in `tests/unit/` directories

### Integration Tests

- Test interactions between modules/components
- May use external services (with mocks where appropriate)
- Moderate execution time (< 1 second per test)
- Located in `tests/integration/` directories

### End-to-End Tests

- Test complete workflows from user perspective
- Use real external services when possible
- Longer execution time
- Located in `tests/e2e/` directories

## Coverage Targets

- **Overall**: 85%+ code coverage
- **Critical paths**: 95%+ code coverage
- **Security-related code**: 100% code coverage

## Test Execution Strategy

### Parallel Execution

- Use `pytest-xdist` for parallel test execution
- Separate test suites to avoid resource contention
- CI pipelines run tests in parallel across multiple machines

### Shift-Left Testing

- Test-driven development (TDD) for new features
- Early validation of assumptions
- Continuous integration with automated testing

## Specialized Testing Approaches

### OpenSearch Failure Mode Testing

- Simulate cluster failures
- Test retry mechanisms and circuit breakers
- Validate data consistency after failures

### Cross-Project Integration Testing

- Mock inter-project communication
- Test authentication and authorization flows
- Validate message integrity and delivery

## Test Markers

- `@pytest.mark.unit`: Unit tests
- `@pytest.mark.integration`: Integration tests
- `@pytest.mark.e2e`: End-to-end tests
- `@pytest.mark.property`: Property-based tests
- `@pytest.mark.opensearch`: Tests involving OpenSearch
- `@pytest.mark.cross_project`: Cross-project integration tests
