LuoChinWen e495e45135 -dev:后端接口开发:任务相关 1 ay önce
..
__pycache__ e495e45135 -dev:后端接口开发:任务相关 1 ay önce
README.md e495e45135 -dev:后端接口开发:任务相关 1 ay önce
__init__.py e495e45135 -dev:后端接口开发:任务相关 1 ay önce
test_database.py e495e45135 -dev:后端接口开发:任务相关 1 ay önce
test_project_api.py e495e45135 -dev:后端接口开发:任务相关 1 ay önce

README.md

Backend Tests

This directory contains all unit and integration tests for the backend application.

Test Structure

  • test_database.py - Database initialization and connection management tests

Running Tests

Run all tests

cd backend
python -m pytest

Run specific test file

python -m pytest test/test_database.py

Run with coverage

python -m pytest --cov=. --cov-report=html

Run specific test class or function

python -m pytest test/test_database.py::TestDatabaseInitialization
python -m pytest test/test_database.py::TestDatabaseInitialization::test_init_database_creates_tables

Test Organization

Tests are organized into classes by functionality:

  • TestDatabaseInitialization: Tests for database table creation and schema validation
  • TestConnectionManagement: Tests for database connection handling and lifecycle
  • TestDatabaseIntegrity: Tests for database constraints and referential integrity

Writing Tests

When adding new tests:

  1. Create test files with test_ prefix (e.g., test_routers_project.py)
  2. Organize tests into classes with Test prefix
  3. Name test functions with test_ prefix
  4. Use descriptive names that explain what is being tested
  5. Add docstrings explaining the test purpose and requirements validated
  6. Use fixtures for common setup/teardown
  7. Follow the Arrange-Act-Assert pattern

Test Coverage

Current test coverage focuses on:

  • ✅ Database initialization (Requirements 9.1)
  • ✅ Connection management (Requirements 9.2)
  • ✅ Table schema validation
  • ✅ Foreign key constraints
  • ✅ Cascade deletes
  • ✅ Transaction handling (commit/rollback)

Dependencies

  • pytest==7.4.3
  • pytest-cov==4.1.0

See requirements.txt for full dependency list.