FastAPI, TestClient (Starlette/httpx üzerine kurulu) ve dependency injection sistemi sayesinde son derece test edilebilirdir; bu, mock'lama işlemini önemsiz hale getirir. Testler tipik olarak pytest ve TestClient kullanarak sunucu çalıştırmadan uygulamaya istek gönderiyor.
Temel endpoint testi TestClient ile
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 ==
