python-testinglisted
Install: claude install-skill martinffx/atelier
# Testing with pytest
Stub-Driven TDD and layer boundary testing patterns for Python applications.
## Core Principle: Stub-Driven TDD
Test at component boundaries, not internal implementation:
```
Router → Service → Repository → Entity → Database
↓ ↓ ↓ ↓
Test Test Test Test
```
Follow the **Stub → Test → Implement → Refactor** workflow:
1. **Stub** - Create function signature with `pass`
2. **Test** - Write test for expected behavior
3. **Implement** - Make test pass
4. **Refactor** - Clean up code
```python
# 1. Stub
def calculate_discount(total: Decimal) -> Decimal:
pass
# 2. Test
def test_discount_for_large_order():
result = calculate_discount(Decimal("150"))
assert result == Decimal("15")
# 3. Implement
def calculate_discount(total: Decimal) -> Decimal:
if total > 100:
return total * Decimal("0.1")
return Decimal("0")
```
## Layer Boundary Testing Overview
Test **what crosses layer boundaries**, not internal implementation:
- **Entity Layer**: Domain logic, validation, transformations (from_request, to_response, to_record)
- **Service Layer**: Business workflows, error handling, dependency orchestration
- **Repository Layer**: CRUD operations, query logic, entity ↔ record transformations
- **Router Layer**: Request validation, response serialization, status codes
See references/boundaries.md for comprehensive layer-specific examples.
## Entity Testing Example
Test transformations and