is this a best practice while performing integration tests on the gRPC services? ie opening and closing channels after each unit test using annotations @BeforeEach and @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 provides junit4 rule called GrpcCleanupRule . Note that it is junit4 rule.
If you're using JUnit 4, you can use the GrpcCleanupRule
. If you're using JUnit 5, you can use the OSS grpc-test I created.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.