FastAPI તેના TestClient (Starlette/httpx પર આધારિત) અને તેની dependency injection સિસ્ટમ માટે આભારી છે, જે dependencies ને mock કરવાનું તુચ્છ બનાવે છે. પરીક્ષણો સામાન્ય રીતે pytest અને TestClient નો ઉપયોગ કરે છે જેથી ચલતા સર્વર વિના app ને requests મોકલી શકાય.
TestClient સાથે મૂળભૂત endpoint પરીક્ષણ
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 ==
