3ccd94f661
Test Organization: - Create tests/unit/, tests/integration/, tests/system/ directories - Move existing tests into appropriate categories - Add pytest markers (@pytest.mark.unit, @pytest.mark.integration) Shared Fixtures: - Create conftest.py with SQLite engine (for unit tests) - Add PostgreSQL session fixture with transaction rollback - Add TestClient fixture for API tests Configuration: - Update pyproject.toml with asyncio_mode=auto - Add test markers and default addopts - Add aiosqlite dependency for SQLite support E2E Testing: - Initialize Playwright in e2e/ directory - Add playwright.config.ts - Create login flow E2E test Build: - Add test-unit, test-integration, test-system, test-e2e to Makefile - Update test target to run all categories - Add testing documentation to README Note: Some tests have import issues due to missing python-jose package in dev environment. This needs to be addressed separately.
2.4 KiB
2.4 KiB
Why
The current test infrastructure has several issues that slow development and reduce confidence:
- Mixed test types in single directory: Unit, integration, and system tests are all mixed together in
apps/api/tests/, making it hard to run fast unit tests independently. - Duplicate fixture code: Database setup/teardown is duplicated across multiple test files instead of using a shared
conftest.py. - Inconsistent test patterns: 4 different patterns exist for database setup (sync helpers, async fixtures, module reloads, autouse env vars).
- No test database isolation: Tests truncate tables manually instead of using transaction rollback, leading to potential data leakage.
- Backend tests require live PostgreSQL: Unit tests that test pure logic still connect to a real database.
- No E2E/system tests: There's no automated way to test the full stack (frontend + API + database) together.
- Import errors in local environment: Tests depend on packages not in
devdependencies (e.g.,python-jose).
What Changes
- Restructure backend tests into
unit/,integration/, andsystem/directories. - Create shared fixtures in
conftest.pyfor database sessions, test client, and authentication. - Add SQLite in-memory support for fast unit tests that don't need PostgreSQL.
- Implement transaction rollback isolation using
begin_nested()for integration tests. - Add missing test dependencies to
pyproject.toml. - Create E2E test setup using Playwright for critical user journeys.
- Add test markers (
@pytest.mark.unit,@pytest.mark.integration,@pytest.mark.system) to enable selective test runs. - Update Makefile with
test-unit,test-integration,test-system, andtest-e2etargets.
Capabilities
New Capabilities
test-organization: Structured test directories with clear separation of concerns.test-isolation: Transaction rollback and SQLite support for fast, isolated tests.e2e-testing: Playwright-based end-to-end tests for critical user journeys.
Modified Capabilities
docker-infrastructure: Add test database service and test runner configuration.
Impact
apps/api/tests/: Restructured into subdirectories.apps/api/pyproject.toml: New test dependencies added.apps/api/conftest.py: New shared fixtures file.Makefile: New test targets.- New
e2e/directory for Playwright tests. - CI pipeline may need updates to run new test categories.