This was answered on Gitter earlier this week, but reposting my response here for anyone who finds this in the future:
We don't have a stand-alone example of unit testing a gRPC service (yet - I > just filed grpc/grpc#17453 <https://github.com/grpc/grpc/issues/17453>). > The APIs documented at https://grpc.io/grpc/python/grpc_testing.html are > what you should be using, but the best I can do right now as far as > pointing you to a "simple" usage of these is the > test_successful_unary_unary method in > https://github.com/grpc/grpc/blob/master/src/python/grpcio_tests/tests/testing/_server_test.py > On Sun, Dec 9, 2018 at 10:27 PM <[email protected]> wrote: > Let's say I have a simple proto: > > service HelloService { > rpc SayHello(HelloReq) returns (HelloResp) {}; > } > > > message HelloReq { > string Name = 1; > } > > > message HelloResp { > string Result = 1; > } > > > > and my SayHello is implemented like: > > class HelloServicer(hello_pb2_grpc.HelloServiceServicer): > > > def SayHello(self, request, context): > if len(request.Name) >= 10: > msg = 'Length of `Name` cannot be more than 10 characters' > context.set_details(msg) > context.set_code(grpc.StatusCode.INVALID_ARGUMENT) > return hello_pb2.HelloResp() > > > return hello_pb2.HelloResp(Result="Hey, {}!".format(request.Name)) > > Can anyone tell me how do I write tests for my server? I checked this repo > - > https://github.com/grpc/grpc/tree/master/src/python/grpcio_tests/tests/testing > or the docs here - https://grpc.io/grpc/python/grpc_testing.html but I > couldn't understand anything at all. > > I really appreciate some help, thank you! > > -- > You received this message because you are subscribed to the Google Groups " > grpc.io" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/grpc-io. > To view this discussion on the web visit > https://groups.google.com/d/msgid/grpc-io/c313a922-3f94-4bdb-9324-fb419b7d2c12%40googlegroups.com > <https://groups.google.com/d/msgid/grpc-io/c313a922-3f94-4bdb-9324-fb419b7d2c12%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "grpc.io" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/grpc-io. To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/CALUXJ7jCMc-mLsBn%2ByhS2T2%3D_oDQw6fusxQGfy1o5UKtNLvtbQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
