2.9 KiB
2.9 KiB
Testing Strategy: Template Mapping Engine
This document outlines the testing strategy for the Template Mapping Engine to ensure production readiness.
1. Backend Testing (Python/FastAPI)
Unit Testing
- Framework:
pytest - Database: Use an in-memory SQLite database (
sqlite:///:memory:) or a dedicated test PostgreSQL container viatestcontainers. - Mocks:
- Mock OCR engines (
pytesseract,pdfplumber) to avoid slow I/O during test suites. - Mock file uploads using
fastapi.testclient.TestClient.
- Mock OCR engines (
- Coverage Targets:
- Engines: 100% logic coverage for
TemplateRecognitionEngineand scoring weights. - Services: 90% coverage for CRUD operations.
- Engines: 100% logic coverage for
Integration Testing
- Test end-to-end API flows:
POST /api/documents/uploadwith a sample PDF.- Wait for layout extraction.
POST /api/templatesto create a template.POST /api/templates/{id}/mappings/saveto map extracted data.POST /api/documents/uploadwith a similar document to verifyPOST /api/documents/{id}/recognizereturns the correct template match.
2. Frontend Testing (Angular)
Unit Testing
- Framework: Jasmine & Karma (or Jest if configured).
- Component Tests:
- Verify
TemplatesComponentrenders the left and right panels. - Verify the
AddFielddialog toggles correctly and validates empty inputs.
- Verify
- Service Tests:
- Mock
HttpClientusingHttpTestingControllerto ensureTemplateServicesends correct payloads to the backend.
- Mock
E2E / Integration Testing
- Framework: Cypress or Playwright.
- Critical User Journeys (CUJ):
- User uploads a document, UI displays the layout preview visually.
- User creates a template and adds 3 fields.
- User drags a block from the Document Preview and drops it into a Template Field.
- User saves the mapping successfully.
3. OCR & Layout Extraction Accuracy Testing
Since the OCR engine relies on visual heuristics rather than AI models, testing its accuracy is crucial to prevent regressions.
- Golden Dataset: Create a dataset of 50-100 real-world business documents (Invoices, POs, Receipts).
- Evaluation Metric: Run the
DocumentProcessorover the Golden Dataset and compare the output bounding boxes and classifications (HEADER, VENDOR, etc.) against manually annotated Ground Truth data. - Acceptance Criteria: Maintain > 92% classification accuracy for logical block types.
4. Performance & Load Testing
- Tool:
locustork6. - Scenario: Simulate 50 concurrent users uploading 2MB PDF documents simultaneously to ensure the
DocumentProcessordoes not exhaust server memory (OpenCV and Tesseract can be memory-intensive). - Optimization: Ensure the
process_filelogic can be offloaded to Celery workers if the API starts blocking or timing out under load.