feat: restructure test infrastructure with unit/integration/system separation
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.
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
## ADDED Requirements
|
||||
|
||||
### Requirement: E2E Test Framework
|
||||
|
||||
The system SHALL provide end-to-end tests using Playwright.
|
||||
|
||||
#### Scenario: Test setup
|
||||
- GIVEN the e2e test directory
|
||||
- THEN `e2e/` SHALL contain Playwright configuration
|
||||
- AND tests SHALL run against the full application stack
|
||||
|
||||
#### Scenario: Critical user journeys
|
||||
- GIVEN the e2e test suite
|
||||
- THEN it SHALL test:
|
||||
- User login flow
|
||||
- Project creation and listing
|
||||
- SSH key generation
|
||||
|
||||
#### Scenario: Test environment
|
||||
- GIVEN e2e tests are running
|
||||
- THEN they SHALL use a dedicated test database
|
||||
- AND tests SHALL clean up data after completion
|
||||
|
||||
### Requirement: Test Commands
|
||||
|
||||
The system SHALL provide Makefile targets for running different test categories.
|
||||
|
||||
#### Scenario: Make targets
|
||||
- GIVEN the Makefile
|
||||
- THEN these targets SHALL exist:
|
||||
- `make test-unit` - Run unit tests only
|
||||
- `make test-integration` - Run integration tests only
|
||||
- `make test-system` - Run system tests only
|
||||
- `make test-e2e` - Run Playwright E2E tests
|
||||
- `make test` - Run all backend tests
|
||||
@@ -0,0 +1,38 @@
|
||||
## ADDED Requirements
|
||||
|
||||
### Requirement: Shared Test Fixtures
|
||||
|
||||
The system SHALL provide shared fixtures in `conftest.py` for common test needs.
|
||||
|
||||
#### Scenario: Database session fixture
|
||||
- GIVEN an integration test
|
||||
- WHEN using the `db_session` fixture
|
||||
- THEN it SHALL provide an async SQLAlchemy session
|
||||
- AND the session SHALL use transaction rollback for isolation
|
||||
|
||||
#### Scenario: Test client fixture
|
||||
- GIVEN an API integration test
|
||||
- WHEN using the `client` fixture
|
||||
- THEN it SHALL provide an authenticated TestClient instance
|
||||
- AND the client SHALL have valid access and refresh tokens
|
||||
|
||||
#### Scenario: SQLite unit test database
|
||||
- GIVEN a unit test
|
||||
- WHEN the test uses the `db_engine` fixture
|
||||
- THEN it SHALL provide an in-memory SQLite engine
|
||||
- AND no PostgreSQL connection SHALL be required
|
||||
|
||||
### Requirement: Transaction Isolation
|
||||
|
||||
The system SHALL ensure integration tests don't pollute the database.
|
||||
|
||||
#### Scenario: Rollback after test
|
||||
- GIVEN an integration test creates data
|
||||
- WHEN the test completes
|
||||
- THEN all database changes SHALL be rolled back
|
||||
- AND subsequent tests SHALL see a clean database state
|
||||
|
||||
#### Scenario: Parallel test safety
|
||||
- GIVEN multiple integration tests run concurrently
|
||||
- WHEN each test uses transaction isolation
|
||||
- THEN tests SHALL not interfere with each other
|
||||
@@ -0,0 +1,36 @@
|
||||
## ADDED Requirements
|
||||
|
||||
### Requirement: Test Directory Structure
|
||||
|
||||
The system SHALL organize tests into unit, integration, and system directories.
|
||||
|
||||
#### Scenario: Directory layout
|
||||
- GIVEN the backend test suite
|
||||
- THEN `apps/api/tests/` SHALL contain:
|
||||
- `unit/` - Pure logic tests with no external dependencies
|
||||
- `integration/` - API endpoint tests with database
|
||||
- `system/` - Full stack tests with external services
|
||||
|
||||
#### Scenario: Running selective tests
|
||||
- GIVEN the test suite is organized
|
||||
- WHEN running `pytest -m unit`
|
||||
- THEN only unit tests SHALL execute
|
||||
- AND WHEN running `pytest -m integration`
|
||||
- THEN only integration tests SHALL execute
|
||||
|
||||
### Requirement: Test Markers
|
||||
|
||||
The system SHALL provide pytest markers for each test category.
|
||||
|
||||
#### Scenario: Marker registration
|
||||
- GIVEN pytest configuration
|
||||
- THEN `pyproject.toml` SHALL register markers:
|
||||
- `unit` - Fast tests with no external dependencies
|
||||
- `integration` - Tests with database and external services
|
||||
- `system` - End-to-end tests of the full stack
|
||||
|
||||
#### Scenario: Marker usage
|
||||
- GIVEN a test file
|
||||
- THEN unit tests SHALL be marked with `@pytest.mark.unit`
|
||||
- AND integration tests SHALL be marked with `@pytest.mark.integration`
|
||||
- AND system tests SHALL be marked with `@pytest.mark.system`
|
||||
Reference in New Issue
Block a user