grpc C++ unit testing rpc services

445 views
Skip to first unread message

smita deshpande

unread,
Nov 3, 2023, 2:16:35 PM11/3/23
to grpc.io
Hi, 

I am new to grpc, is there any documentation or examples explaining unit testing of server side RPC calls/services?

Thanks,
Smita

Eugene Ostroukhov

unread,
Nov 7, 2023, 1:18:01 PM11/7/23
to grpc.io
This is an open-ended question and depends a lot on the granularity of the tests you want. We have unit tests that test the service class directly. Sometimes we start a service on a background thread and then connect to it from the test.

There is no premade test harness that I know of. This is an example of running the server in-process: reflection test.

smita deshpande

unread,
Nov 7, 2023, 3:48:27 PM11/7/23
to grpc.io
I am thinking of mocking the interface grpc::internal::ServerAsyncStreamingInterface
in case of testing async server. So it would become possible to even use google Unit tests. I am having simple hello world unary call. However, I do not want to run server and test the SayHello RPC service with real client and server.

Do you think its good idea?

Thanks,
Smita

Eugene Ostroukhov

unread,
Nov 7, 2023, 3:58:02 PM11/7/23
to smita deshpande, grpc.io
I would advise against mocking internal interfaces. That may make the tests increasingly brittle when you update gRPC version. Also, it may reduce the test coverage.

--
You received this message because you are subscribed to a topic in the Google Groups "grpc.io" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/grpc-io/h0BYoxKv63M/unsubscribe.
To unsubscribe from this group and all its topics, send an email to grpc-io+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/6038c4a0-2d56-4459-ae9d-50862602cce9n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages