FastAPI je zelo testabilen zahvaljujoč TestClient (zgrajen na Starlette/httpx) in njegovemu sistemu vbrizgavanja odvisnosti, kar naredi mocking odvisnosti trivialen. Testi običajno uporabljajo pytest in TestClient za pošiljanje zahtevkov aplikaciji brez zagnanega strežnika.
Osnovni test končne točke s 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 ==
