簡體   English   中英

單元測試 gRPC 的最佳實踐

[英]Best practice for unit testing gRPC

這是對 gRPC 服務執行集成測試時的最佳實踐嗎? 即在每次單元測試后使用注解@BeforeEach 和@AfterEach 打開和關閉通道

private ManagedChannel channel;

private DepartmentServiceGrpc.DepartmentServiceBlockingStub deptService;

@BeforeEach
public void initEach(){
    channel = ManagedChannelBuilder.forAddress("localhost", 8080)
            .usePlaintext()
            .build();

    deptService = DeptServiceGrpc.newBlockingStub(channel);
}

@AfterEach
public void cleanUpEach(){
    channel.shutdown();
}

gRPC 提供稱為GrpcCleanupRule 的junit4 規則。 請注意,這是junit4規則。

如果您使用的是 JUnit 4,則可以使用GrpcCleanupRule 如果您使用的是 JUnit 5,則可以使用我創建的 OSS grpc-test

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM