FastAPI ਆਪਣੇ TestClient (Starlette/httpx ਉੱਤੇ ਬਣਿਆ ਹੋਇਆ) ਅਤੇ ਆਪਣੇ dependency injection ਸਿਸਟਮ ਦੀ ਬਦੌਲਤ ਬਹੁਤ ਸੀ ਪਰੀਖਿਆ ਯੋਗ ਹੈ, ਜੋ mock dependencies ਨੂੰ ਅਸਾਨ ਬਣਾਉਂਦਾ ਹੈ। ਟੈਸਟ ਆਮ ਤੌਰ 'ਤੇ pytest ਅਤੇ TestClient ਦੀ ਵਰਤੋਂ ਕਰਕੇ ਐਪ ਨੂੰ ਬਿਨਾਂ ਚਲ ਰਹੀ ਸਰਵਰ ਦੇ ਬੇਨਤੀਆਂ ਭੇਜਦੇ ਹਨ।
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 ==
