Files
calminer/docs/testing.md
zwitschi 39c45e720c Add initial implementation of CalMiner with project structure, environment setup, and core features
- Create .env.example for environment variables
- Update README with project structure and development setup instructions
- Implement FastAPI application with API routes for scenarios and parameters
- Add database models for scenarios, parameters, and simulation results
- Introduce validation middleware for JSON requests
- Create services for running simulations and generating reports
- Add testing strategy and directory structure in documentation
2025-10-20 18:37:57 +02:00

75 lines
1.8 KiB
Markdown

# Testing Strategy
## Overview
CalMiner will use a combination of unit, integration, and end-to-end tests to ensure quality.
## Frameworks
- **Backend**: pytest for unit and integration tests.
- **Frontend**: (TBD) pytest with Selenium or Playwright.
- **Database**: pytest fixtures with psycopg2 for DB tests.
## Test Types
- **Unit Tests**: Test individual functions/modules.
- **Integration Tests**: Test API endpoints and DB interactions.
- **E2E Tests**: (Future) Playwright for full user flows.
## CI/CD
- Use GitHub Actions for CI.
- Run tests on pull requests.
- Code coverage target: 80% (using pytest-cov).
## Running Tests
- Unit: `pytest tests/unit/`
- Integration: `pytest tests/integration/`
- All: `pytest`
## Test Directory Structure
Organize tests under the `tests/` directory mirroring the application structure:
```bash
tests/
unit/
test_<module>.py
integration/
test_<endpoint>.py
fixtures/
conftest.py
```
## Writing Tests
- Name tests with the `test_` prefix.
- Group related tests in classes or modules.
- Use descriptive assertion messages.
## Fixtures and Test Data
- Define reusable fixtures in `tests/fixtures/conftest.py`.
- Use temporary in-memory databases or isolated schemas for DB tests.
- Load sample data via fixtures for consistent test environments.
## Mocking and Dependency Injection
- Use `unittest.mock` to mock external dependencies.
- Inject dependencies via function parameters or FastAPI's dependency overrides in tests.
## Code Coverage
- Install `pytest-cov` to generate coverage reports.
- Run with coverage: `pytest --cov=calminer --cov-report=html`.
- Ensure coverage meets the 80% threshold.
## CI Integration
- Configure GitHub Actions workflow in `.github/workflows/ci.yml` to:
- Install dependencies
- Run `pytest` with coverage
- Fail on coverage <80%
- Upload coverage artifact