Grpc-java: Provide JUnit 5 GrpcTestExtension

Created on 7 Feb 2019  路  10Comments  路  Source: grpc/grpc-java

What version of gRPC are you using?

1.18.0

What did you expect to see?

In order to be able to test with JUnit 5 I would like to have a comparable solution like GrpcCleanupRule but as JUnit 5 extension.

Example

In my PoC project mmichaelis/poc-grpc you may see an example, which is very similar to your GrpcCleanupRule (because that was my intention :smile:): In module grpc-test you will find the class GrpcTestExtension and an example usage in HelloServiceImplTest.

Help wanted?

I may assist in adding this to the grpc-java project, but there are several questions:

  • First of all: Do you like the extension?
  • Where to place the JUnit 5 extension? Into testing module? Or an extra module?
  • And if it is an extra module: How to share code? My intention would be to refactor GrpcCleanupRule, so that GrpcTestExtension and the JUnit 4 rule share as much code as possible.

Most helpful comment

@marcphilipp Added to the "JUnit Jupiter Extensions" section.

All 10 comments

This seems need to add junit 5 dependency in io.grpc.testing. @carl-mastrangelo are we able to add that dependency internally?

personally i would like to use junit5. but, internally we only have junit 4.12. junit5 requires pretty big change, so unfortunately it won't happen any time in near future.

JUnit 5 is also Java 8+. I'm not sure if the grpc-testing module is still under of the umbrella of https://github.com/grpc/grpc-java/issues/4671

Just wondering how this issue is going? Is there anything I can do to help?

@Torbacka , basically it is blocked by #4671. grpc-java is a library that still has to support Java 7.

@dapengzhang0 thank for the update.

IMO the current design of GrpcCleanupRule is unnecessarily dependent on Junit4 TestRule api. It basically calls teardown method after each test case.

So, I guess, if you can just separate the core cleanup utility from the TestRule extension, we can just call tearDown() method inside @AfterEach method. Or use the engine to create a Junit5 AfterEachCallback extension.

I created an extension for JUnit 5, that does what the rule did, and more. https://github.com/asarkar/grpc-test

@asarkar Awesome! Could you please add it to https://github.com/junit-team/junit5/wiki/Third-party-Extensions?

@marcphilipp Added to the "JUnit Jupiter Extensions" section.

Was this page helpful?
0 / 5 - 0 ratings