FastAPIは、その**TestClient(Starlette/httpxの上に構築されている)と、依存性のモック化を簡単にする依存性注入**システムのおかげで、非常にテストしやすいフレームワークです。テストは通常、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 ==
