【发布时间】:2019-01-18 10:17:07
【问题描述】:
我想使用 Python unittest 为我的 GRPC 服务器实现编写测试。我找到了 grpcio-testing 包,但我找不到任何文档如何使用它。
假设我有以下server:
import helloworld_pb2
import helloworld_pb2_grpc
class Greeter(helloworld_pb2_grpc.GreeterServicer):
def SayHello(self, request, context):
return helloworld_pb2.HelloReply(message='Hello, %s!' % request.name)
如何创建单元测试来调用SayHello 并检查响应?
【问题讨论】:
-
将代码用作文档 - python 库主要是您可以阅读的 python 代码。这个问题在这里是题外话,因为你必须提供一些代码尝试并提出一个特定的问题。
-
代码没有文档。见here。我为服务器添加了代码。
-
@Mitar 我认为 nosklo 建议您深入研究 grpcio-testing 的代码以了解如何使用它。
-
是的,我已经这样做了,但我无法弄清楚。所以我来到这个很棒的网站寻求帮助。可能这个站点上的任何开源编程问题都可以用“阅读代码并弄清楚”来回答。我认为这个网站不存在这样的答案。