Với endpoint sync/normal, dùng TestClient. Với async test cần gọi async DB/client, dùng pytest.mark.anyio và httpx.AsyncClient hoặc ASGI transport.
Ví dụ override dependency:
python
app.dependency_overrides[get_current_user] = lambda: User(id=1, email="a@example.com")
client = TestClient(app)
response = client.get("/me")
assert response.status_code == 200Test tốt nên cover status code, response schema, auth path, validation lỗi 422 và side effect quan trọng.