[C++] Server Mocking for Unit Testing (mock stream)

45 views
Skip to first unread message

Alex Shaver

unread,
Jul 6, 2018, 8:23:36 AM7/6/18
to grpc.io
When I have a service that has a simple unary interaction, writing a unit test for the ServiceImpl is straightforward enough, does the impl put the right protobuf into the response parameter of the function. When I have a service that has a streaming interaction, a streaming object (ServerWriter, eg) is injected as a parameter giving you the capacity to write out to that stream. It seems to me, somewhat naively, that this should be a 'ServerWriterInterface' pointer, rather than a ServerWriter itself (which is marked as final), so that you could inject a MockServerWriter object and count how many times "Write" got called and with what protos.

Which possibly says to me that I'm missing something on how one goes about testing Services. The online tutorial/documentation goes into detail about how one can mock out a stub for C++ client code so that can be unit tested easily. But it's not clear to me how to go about mocking the Service side.

Yang Gao

unread,
Aug 6, 2018, 6:16:11 PM8/6/18
to grpc.io
You are right. Currently there is no support for mocking server side sync reader/writer objects.. and it can only be tested with a real client and grpc library.
Reply all
Reply to author
Forward
0 new messages