[serve] Add docs on best practices for testing
Copy-pasting from what I told a user:
I’d suggest structuring your application like this:
class MyModel:
# Implement logic here.
...
@serve.deployment(...)
class MyModelDeployment(MyModel):
# Define fastapi routes here.
pass
That way you can rewrite true unit tests against business logic in MyModel. For integration testing, I haven’t tested the fastapi test client, but I don’t think it will work directly. I’d suggest using requests to send HTTP requests after using serve.run to run the app locally. You can also test using Python DeploymentHandle calls like this: handle: ray.serve.handleDeploymentHandle = serve.run(MyModelDeployment.bind()) handle.method.remote().result() # Calls the app method "method" and returns the result.
Closing: the Development Workflow guide now covers testing with serve.run and handles, serve run over HTTP, local testing mode for unit tests, and remote clusters.