Test gRPC server without Serve?

93 views
Skip to first unread message

Bendegúz Csirmaz

unread,
Mar 16, 2026, 5:09:12 PM (5 days ago) Mar 16
to grpc.io
Is it possible to send in a gRPC request without the gRPC server running?

I know this may sound like a silly question and I know the answer is probably no... let me elaborate

In Django, there's a test client. It makes it possible to simulate requests in integration tests. So you don't have to start a Django server to test the API. I was wondering if there's something similar in gRPC? I'm using Go by the way

The goal is to implement transactional tests, so the database is rolled back after each test

- I am aware of bufconn.Listener which is nice but still needs to run the server separately. Should I start the server for every single test?
- Alternatively, I could test the handlers only

I am open to suggestions, thanks!

Easwar Swaminathan

unread,
Mar 18, 2026, 2:13:34 AM (4 days ago) Mar 18
to grpc.io
The recommended way in Go is generally to use a real client talking to a test double. See: https://google.github.io/styleguide/go/best-practices#use-real-transports.

Also FYI, most tests in the grpc-go repository use a real grpc server unless we want to test something at the HTTP/2 layer.

Bendegúz Csirmaz

unread,
Mar 18, 2026, 4:33:25 AM (4 days ago) Mar 18
to grpc.io
Thank you for taking the time to answer Easwar!

I tried mocking the gRPC stream object for testing a handler and I have to agree it's better to use a real client

What I'm worried about is:
1. The cost of starting a gRPC server for each test - isn't that too slow?
2. How to tear down the test data:
  a) Should I create a new test db for each test?
  b) Should I inject a transaction in the server somehow that I can rollback after the test?

I suppose:
1. Starting a server listening on bufconn per test is fine. This seems to be the standard and this is what you're also recommending correct?
2. How to tear down is up to the developer... if somebody has examples of this I would love to see that

Daz Wilkin

unread,
Mar 19, 2026, 6:43:03 PM (2 days ago) Mar 19
to grpc.io
See FauxRPC too.

It generates server implementations from protos to facilitate testing.

On Monday, March 16, 2026 at 2:09:12 PM UTC-7 Bendegúz Csirmaz wrote:

Bendegúz Csirmaz

unread,
Mar 20, 2026, 5:25:26 AM (2 days ago) Mar 20
to grpc.io
Thank you Daz!

That's a nice tool, good for a creating a test double of the OperationsServer - as per the Google styleguide Easwar linked:
use a real OperationsClient that is connected to a test double (e.g., a mock, stub, or fake) of the OperationsServer

I'm more interested in testing the server (integration tests), but I will keep a note of that

Reply all
Reply to author
Forward
0 new messages