FastAPI는 TestClient(Starlette/httpx 기반)와 의존성을 목으로 만드는 것을 손쉽게 하는 dependency injection 시스템 덕분에 테스트하기 매우 좋습니다. 테스트는 일반적으로 pytest와 TestClient를 사용해, 실행 중인 서버 없이 앱에 요청을 보냅니다.
TestClient로 기본 엔드포인트 테스트
fastapi.testclient TestClient
main app
client = TestClient(app)
():
response = client.get()
response.status_code ==
response.json() == {: }
():
response = client.post(, json={: , : })
response.status_code ==
response.json()[] ==
():
response = client.post(, json={: })
response.status_code ==
