A comprehensive test suite for the Products CRUD API using httpx
for parallel test execution.
- Async/Parallel Testing: Uses
httpx
for concurrent HTTP requests - Comprehensive Coverage: Happy path, edge cases, error handling, and more
- Modular Structure: Organized by test categories for easy maintenance
- Automatic Cleanup: Test fixtures handle resource cleanup automatically
- Faker Integration: Generates realistic test data
- Product creation with all field combinations
- Product retrieval with pagination scenarios
- Product updates (partial and complete)
- Product deletion
- Root endpoint access
- Parallel operations testing
- Input Validation Tests
- Edge Case Tests
- Error Handling Tests
- Business Logic Tests
- Security Tests
- Performance Tests
- Integration Tests
- Install test dependencies:
pip install -r requirements-test.txt
- Configure your API base URL in
tests/conftest.py
:
BASE_URL = "http://localhost:8000" # Update this to match your API server
# Install dependencies
python run_tests.py install
# Run happy path tests only
python run_tests.py happy
# Run all tests
python run_tests.py all
# Run tests with coverage report
python run_tests.py coverage
# Run tests in parallel
python run_tests.py parallel
# Run happy path tests
pytest tests/test_happy_path.py -v -m happy_path
# Run all tests
pytest tests/ -v
# Run tests in parallel with auto CPU detection
pytest tests/ -n auto
# Run with coverage
pytest tests/ --cov=. --cov-report=html
tests/
├── conftest.py # Test fixtures and configuration
├── test_happy_path.py # Happy path test scenarios
└── (more test files to be added)
Tests are designed to run concurrently using httpx.AsyncClient
, significantly reducing execution time.
- Products created during tests are automatically cleaned up
- Fixtures handle setup and teardown
- No manual cleanup required
- Product Creation: All field combinations, boundary values
- Product Retrieval: Pagination scenarios, individual product access
- Product Updates: Partial and complete updates
- Product Deletion: With verification
- Parallel Operations: Concurrent create/read operations
Uses Faker library to generate realistic test data, ensuring tests don't rely on hardcoded values.
- Configures async test mode
- Sets test discovery patterns
- Defines custom markers
- HTTP client fixture with proper timeout and headers
- Sample data generators
- Resource cleanup utilities
- Created product fixtures for easy testing
The test suite is designed for incremental implementation. After running the happy path tests successfully, you can implement additional test categories:
- Input Validation Tests
- Edge Case Tests
- Error Handling Tests
- Business Logic Tests
- Security Tests
- Performance Tests
- Integration Tests
Each category will follow the same async/parallel pattern established in the happy path tests.