Testing Strategy
Relevant source files
The following files were used as context for generating this wiki page:
The FLEXT gRPC testing strategy is built upon enterprise-grade standards, emphasizing isolation, comprehensive coverage, and deterministic results. The suite is designed to validate the entire communication platform, ranging from core domain entities and configurations to high-level API functions and complete gRPC workflows. The primary objective is to maintain high code quality and reliability through a multi-layered testing architecture that integrates unit, integration, and end-to-end (E2E) tests.
Sources: tests/README.md:1-25, tests/unit/test_errors.py:1-35
Testing Architecture and Organization
The project employs a structured directory layout to separate tests based on their scope and dependencies. This organization ensures that fast-running unit tests remain isolated from slower integration and E2E tests.
The architecture facilitates clear separation of concerns, where conftest.py provides shared fixtures and environment setup across all categories.
Sources: tests/README.md:27-46
Test Categories and Standards
Testing is categorized into three main tiers, each with specific performance and isolation requirements.
| Category | Scope | Dependencies | Performance Standard |
|---|---|---|---|
| Unit Tests | Domain entities, services, types, and API functions | Mocked external dependencies | < 100ms per test |
| Integration Tests | Platform integration, service coordination, DI validation | Real dependencies in controlled env | < 1s per test |
| End-to-End (E2E) | Full gRPC client-server communication workflows | Real/near-real environment | < 10s per test |
Sources: tests/README.md:52-110, tests/README.md:213-221
Unit Testing Patterns
Unit tests are the foundation of the strategy, focusing on domain logic and error handling in complete isolation.
Domain Entity and API Testing
The FlextGrpc facade and associated API functions are validated for correct instantiation and resource creation. Tests cover the creation of servers, clients, channels, and services, ensuring that properties are correctly mapped and validation rules are enforced.
Sources: tests/unit/test_api.py:16-95
Configuration Validation
Configuration testing validates the FlextGrpcSettings model, ensuring environment variables are correctly parsed and business rules (e.g., TLS requirements for client certificates) are strictly followed.
Sources: tests/unit/test_config.py:38-118
Error Hierarchy Testing
The error system is tested for proper inheritance from the flext-core base error classes and for the inclusion of specific contextual metadata, such as field names in validation errors or config_key in configuration errors.
Sources: tests/unit/test_errors.py:53-150
Quality Gates and Performance
The project enforces strict quality gates within the CI pipeline. These gates ensure that no code is deployed without meeting minimum reliability and documentation thresholds.
- Coverage Requirement: Minimum 90% target (module-specific targets vary, with
types.pyanderrors.pyalready at 100%). - Zero Tolerance: All tests must pass; no linting errors (Ruff) or type errors (MyPy) are permitted.
- AAA Pattern: Tests must follow the Arrange, Act, Assert structure.
- Documentation: 100% docstring coverage for all test modules.
Sources: tests/README.md:48-51, tests/README.md:144-150, tests/README.md:225-230, pyproject.toml:570-585
Pytest Configuration and Tooling
The testing suite utilizes several pytest plugins and custom markers to manage execution and reporting.
Sources: pyproject.toml:98-115
Custom Test Markers
Tests are categorized using markers defined in pyproject.toml and tests/README.md to allow for selective execution:
@pytest.mark.unit: Fast, isolated tests.@pytest.mark.integration: Component interaction.@pytest.mark.e2e: Complete workflows.@pytest.mark.slow: Tests that can be skipped for quick feedback loops.
Sources: tests/README.md:124-131, pyproject.toml:500-515
Conclusion
The FLEXT gRPC testing strategy prioritizes a "Fix-Forward-Only" approach and strict adherence to the Result pattern for error handling. By combining high coverage requirements with isolated unit tests and real-world E2E scenarios, the strategy ensures the platform remains robust, performant, and maintainable.
Sources: tests/README.md:235-240, tests/unit/test_errors.py:165-180