Skip to content

Testing Strategy

RAG Modulo employs a comprehensive testing strategy with 947+ automated tests organized by speed and scope.

Test Organization

Test Categories

Tests are organized into four main categories:

  1. Atomic Tests (Fastest - ~5 seconds)
  2. Schema and data structure validation
  3. Pydantic model tests
  4. No database required

  5. Unit Tests (Fast - ~30 seconds)

  6. Individual function/class testing
  7. Mocked dependencies
  8. No external services

  9. Integration Tests (Medium - ~2 minutes)

  10. Service interaction tests
  11. Real database operations
  12. Vector database integration

  13. End-to-End Tests (Slower - ~5 minutes)

  14. Full system tests
  15. API to database workflows
  16. Complete feature validation

Test Markers

Tests use pytest markers for categorization:

  • @pytest.mark.atomic - Atomic schema tests
  • @pytest.mark.unit - Unit tests
  • @pytest.mark.integration - Integration tests
  • @pytest.mark.e2e - End-to-end tests
  • @pytest.mark.api - API endpoint tests
  • @pytest.mark.performance - Performance benchmarks

Running Tests

See Running Tests for detailed commands and usage.

Test Coverage

  • Minimum Coverage: 60%
  • Current Tests: 947+ automated tests
  • Coverage Report: make coverage (generates HTML report)

Testing Best Practices

Unit Testing

  • Mock external dependencies
  • Test one component at a time
  • Use fixtures for common setup
  • Keep tests fast and isolated

Integration Testing

  • Use real services (Postgres, Milvus)
  • Test service interactions
  • Validate data persistence
  • Clean up test data

End-to-End Testing

  • Test complete workflows
  • Validate API contracts
  • Test error handling
  • Verify business logic

Test Fixtures

Common fixtures are defined in tests/conftest.py:

  • db_session - Database session
  • test_client - FastAPI test client
  • sample_user - Mock user for testing
  • sample_collection - Mock collection data

Continuous Integration

All tests run in CI/CD pipeline:

  • On Every PR: Atomic + Unit tests (~2 min)
  • On Push to Main: All tests including integration (~5 min)

See CI/CD Documentation for details.

Test Organization Structure

tests/
โ”œโ”€โ”€ unit/           # Unit tests with mocks
โ”‚   โ”œโ”€โ”€ services/   # Service layer tests
โ”‚   โ”œโ”€โ”€ repository/ # Repository layer tests
โ”‚   โ””โ”€โ”€ schemas/    # Schema validation tests
โ”œโ”€โ”€ integration/    # Integration tests with real services
โ”œโ”€โ”€ api/            # API endpoint tests
โ””โ”€โ”€ performance/    # Performance benchmarks

Writing New Tests

  1. Determine Test Type
  2. Atomic: Schema/model validation
  3. Unit: Single component with mocks
  4. Integration: Multiple components with real services
  5. E2E: Full workflow testing

  6. Add Appropriate Markers

    @pytest.mark.unit
    def test_search_service_query():
        # Test implementation
    

  7. Use Fixtures

    def test_create_collection(db_session, sample_user):
        # Test using fixtures
    

  8. Assert Clearly

  9. Use descriptive assertions
  10. Test both success and failure cases
  11. Validate error messages

See Also