Skip to content

Testing Guide

Comprehensive testing strategy for Certana.

Testing Pyramid

        /\
       /  \
      /Unit \       100+ tests
     /______\
      /    \
     /  Int \      20-50 tests
    /________\
     /      \
    / E2E    \    5-10 tests
   /________\

Backend Testing

Unit Tests

import pytest
from unittest.mock import patch

@pytest.mark.asyncio
async def test_extract_watermark():
    """Test watermark extraction"""
    image = create_test_image()
    result = extract_watermark(image)
    assert result is not None

Integration Tests

@pytest.mark.asyncio
async def test_upload_asset_end_to_end(db):
    """Test complete asset upload flow"""
    # Upload
    # Verify processing
    # Check database
    # Verify storage

Running Tests

# All tests
pytest

# With coverage
pytest --cov=src

# Specific test
pytest tests/test_assets.py::test_upload_asset

Frontend Testing

Component Tests

import { render, screen } from '@testing-library/react-native';

test('renders verification button', () => {
  render(<ImageVerifier />);
  expect(screen.getByText('Verify')).toBeTruthy();
});

Running Tests

npm test
npm test -- --coverage
npm test -- --watch

Test Coverage Targets

  • Backend: > 80%
  • Frontend: > 70%
  • Critical paths: 100%

Continuous Integration

Tests run automatically on: - Pull requests - Commits to main/develop - Before deployment

See CI/CD Pipeline.

Mocking & Fixtures

@pytest.fixture
def mock_storage_service():
    with patch('src.services.StorageService') as mock:
        yield mock

@pytest.fixture
def test_image():
    return np.random.randint(0, 255, (224, 224, 3), dtype=np.uint8)

Best Practices

  • Write tests as you code
  • One assertion per test
  • Use fixtures for setup
  • Mock external dependencies
  • Test edge cases
  • Keep tests maintainable