creator-o1
Initial commit: Complete VoiceForge Enterprise Speech AI Platform
d00203b

VoiceForge Testing Guide

Overview

VoiceForge uses a comprehensive, multi-layered testing strategy to ensure code quality, security, and performance.

Test Structure

backend/tests/
β”œβ”€β”€ unit/                    # Service-level unit tests
β”‚   β”œβ”€β”€ test_stt_service.py
β”‚   β”œβ”€β”€ test_tts_service.py
β”‚   β”œβ”€β”€ test_translation_service.py
β”‚   β”œβ”€β”€ test_emotion_meeting_service.py
β”‚   β”œβ”€β”€ test_audio.py
β”‚   β”œβ”€β”€ test_cloning.py
β”‚   β”œβ”€β”€ test_export.py
β”‚   β”œβ”€β”€ test_nlp.py
β”‚   └── test_sign.py
β”œβ”€β”€ integration/             # API & E2E tests
β”‚   β”œβ”€β”€ test_auth.py
β”‚   β”œβ”€β”€ test_api_integration.py
β”‚   β”œβ”€β”€ test_e2e_full_flow.py
β”‚   β”œβ”€β”€ test_diarization.py
β”‚   └── test_project_health.py
β”œβ”€β”€ performance/             # Load & benchmark tests
β”‚   β”œβ”€β”€ locustfile.py
β”‚   β”œβ”€β”€ benchmark_*.py
β”‚   └── run_benchmarks.py
β”œβ”€β”€ quality/                 # Code quality tools
β”‚   β”œβ”€β”€ analyze_codebase.py
β”‚   β”œβ”€β”€ check_syntax.py
β”‚   β”œβ”€β”€ check_dependencies.py
β”‚   β”œβ”€β”€ check_pipeline.py
β”‚   β”œβ”€β”€ coverage_tracker.py
β”‚   β”œβ”€β”€ lighthouse_audit.py
β”‚   └── project_audit.py
β”œβ”€β”€ security/                # Security audits
β”‚   └── run_audit.py
β”œβ”€β”€ conftest.py              # Shared fixtures
β”œβ”€β”€ pytest.ini               # Pytest configuration
└── run_all_tests.py         # Master test runner

Running Tests

Quick Start

cd backend
python tests/run_all_tests.py

Individual Test Categories

# Unit tests
pytest tests/unit -v

# Integration tests
pytest tests/integration -v

# Performance benchmarks
python tests/performance/run_benchmarks.py

# Security audit
python tests/security/run_audit.py

Docker (Recommended)

# Run all tests in clean Docker environment
docker-compose run --rm backend python tests/run_all_tests.py

# Run specific category
docker-compose run --rm backend pytest tests/unit -v

Quality Tools

Code Quality Analysis

python tests/quality/analyze_codebase.py --path app

Checks:

  • File sizes (flags >500 lines)
  • Cyclomatic complexity (Radon)
  • Maintainability index
  • Long functions (>50 lines)
  • Import dependencies

Syntax & Import Check

python tests/quality/check_syntax.py --path app

Checks:

  • Python syntax errors
  • Circular imports
  • Missing __init__.py files

Dependency Health

python tests/quality/check_dependencies.py

Checks:

  • Local pip compatibility (pip check)
  • PyPI availability (online check)
  • Outdated packages
  • Security vulnerabilities (via pip-audit)

Pipeline Validation

python tests/quality/check_pipeline.py --root ..

Checks:

  • GitHub Actions workflow syntax
  • Dockerfile validation
  • docker-compose.yml structure
  • Environment file presence

Coverage Tracking

python tests/quality/coverage_tracker.py --app app --tests tests

Provides:

  • Module coverage matrix
  • Untested function identification
  • Coverage percentage by component

Frontend Performance (Lighthouse)

python tests/quality/lighthouse_audit.py --url http://localhost:8501

Audits:

  • Performance score
  • Accessibility score
  • Best practices
  • SEO metrics

Test Fixtures

Database Setup

@pytest.fixture(scope="module")
def setup_db():
    Base.metadata.create_all(bind=engine)
    yield
    # Cleanup optional

Test Client (Sync)

@pytest.fixture
def client():
    return TestClient(app)

Async Client

@pytest_asyncio.fixture
async def async_client():
    transport = ASGITransport(app=app)
    async with AsyncClient(transport=transport, base_url="http://test") as client:
        yield client

Best Practices

Writing Unit Tests

  • Test one function per test case
  • Use mocks for external dependencies
  • Follow AAA pattern (Arrange, Act, Assert)
@pytest.mark.asyncio
async def test_synthesize_returns_audio_bytes():
    # Arrange
    with patch('app.services.edge_tts_service.EdgeTTSService') as MockService:
        mock_service = MockService.return_value
        mock_service.synthesize = AsyncMock(return_value=b'AUDIO_DATA')
        
        # Act
        audio = await mock_service.synthesize("Hello", voice="en-US-Neural2-F")
        
        # Assert
        assert isinstance(audio, bytes)
        assert len(audio) > 0

Writing Integration Tests

  • Test realistic user flows
  • Use actual database (with cleanup)
  • Test authentication & authorization
def test_full_user_journey(client):
    # Register
    response = client.post("/api/v1/auth/register", json={...})
    assert response.status_code == 200
    
    # Login
    response = client.post("/api/v1/auth/login", data={...})
    token = response.json()["access_token"]
    
    # Use protected endpoint
    response = client.get("/api/v1/auth/me", headers={"Authorization": f"Bearer {token}"})
    assert response.status_code == 200

CI/CD Integration

GitHub Actions Workflow

name: Test Suite
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Run tests
        run: |
          docker-compose run --rm backend python tests/run_all_tests.py

Coverage Goals

  • Unit Tests: >80% line coverage
  • Integration Tests: All critical user flows
  • Performance: All endpoints benchmarked
  • Security: Zero high/critical vulnerabilities

Current Status

βœ… 74+ tests across all categories
βœ… 100% module coverage (all services have tests)
βœ… 7 quality tools for automated analysis
βœ… Master runner for one-command execution