-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide JUnit 5 GrpcTestExtension #5331
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 |
Just wondering how this issue is going? Is there anything I can do to help? |
@dapengzhang0 thank for the update. |
IMO the current design of So, I guess, if you can just separate the core cleanup utility from the |
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. |
any update on this? |
@xmlking |
Unfortunately my corporate nexus blocking some external dependencies |
Not sure I understand how grpc-java would be allowed, but grpc-test wouldn't be, given both are available on Maven Central. Good luck. |
I just came across this issue. Even if we assume Java 7 support was dropped today, I'm not sure grpc-testing in the appropriate place to put JUnit 5 stuff. It seems fair to make a separate artifact for it (e.g., Dropping Java 7 support will be very soon now, but I don't think there's any need to wait on it. Unless there's disagreement that another artifact is appropriate. I will say that I don't understand JUnit 5 (it has scared me off each time I've glanced; I had issues with JUnit 3 so welcomed 4, but don't understand why we need the redesign of 5), so this will probably need community guidance on best practices for obvious stuff. I do think we liked the simple-and-get-out-of-your-way approach of GrpcCleanupRule, so I'd hope making the extension is straight-forward with few design questions. Although glancing at asarkar/grpc-test (even if I can't read Kotlin) makes me worry that isn't the case. I'm not against copying (or similar) asarkar/grpc-test, assuming that @asarkar is fine with that and we (as a community) halfway like the approach. It has existed for years and seems like it works. But I will need someone to explain to me why, oh, why do we need |
Hi @ejona86
Assuming you're referring to this line, this is required to support the use cases 2 and 3 documented in the README.
JUnit doesn't provide access to instance or static fields, only test method parameters. The JUnit 4 rule doesn't support these use cases, and hence is relatively simpler. I made the code available under Apache License v2.0, so if you want to fork it honoring the terms in the license, I've no problems with that. It's not clear to me though where the code will live after copying, since you seem to be recommending making a separate artifact. If that's the case, what's wrong with the the existing artifact? You, or anyone from the gRPC or JUnit team, are welcome to contribute to my repo if you choose to. |
The JUnit 4 rule supports instance field and static field, without reflection (in its code). It only doesn't support method parameter. It seems bizarre to me that JUnit 5 would start using setAccessible(true) more heavily, but I do agree that seems to be the case. Strange that people like the idea of a Honestly, it feels like JUnit 5 just doesn't care about resources any more. Writing an extension for every resource type is silly and seems a horrible idea (since it uses |
JUnit 5's use of |
@jon-abdulloev-globality Java version, as in Java source code? No. Why do you ask? |
i can solve the problem, we only use GrpcServerRule.java when i change the next call:
and i used now:
but for this i had to change the class GrpcServerRule, i had to create the class in my proyect in Junit5 the next way:
|
This allows using GrpcCleanupRule with JUnit 5 when combined with ExternalResourceSupport. We don't really lose anything important when running with JUnit 4 and this eases migration to JUnit 5. ExternalResource is now responsible for combining exceptions. after() cannot throw checked exceptions, so we must now wrap the InterruptedException. When used with JUnit 5 we are unable to detect the test failed; we accept that for now but it may be fair to create a new class for JUnit 5 to be used with `@RegisterExtension` that implements BeforeEachCallback and AfterTestExecutionCallback to restore the JUnit 4 behavior. See grpc#5331
#9240 will improve JUnit 5 compatibility for GrpcCleanupRule. However, in JUnit 5 it won't know if the test failed, so if the test method leaves RPCs open on assertion failure (seems fairly likely) then there will be ~10 second of added time. I poked at JUnit 5 more, and I don't think we need anything all that special or to do |
This allows using GrpcCleanupRule with JUnit 5 when combined with ExternalResourceSupport. We don't really lose anything important when running with JUnit 4 and this eases migration to JUnit 5. ExternalResource is now responsible for combining exceptions. after() cannot throw checked exceptions, so we must now wrap the InterruptedException. When used with JUnit 5 we are unable to detect the test failed; we accept that for now but it may be fair to create a new class for JUnit 5 to be used with `@RegisterExtension` that implements BeforeEachCallback and AfterTestExecutionCallback to restore the JUnit 4 behavior. See #5331
Why not just use the @asarkar's solution? |
@Tomasan7, it is available separately. If you like it, you can use it. |
@lewimuchiri |
@asarkar and others - I struggled to understand how to replace the JUnit5 examples with existing so I started searching on github for examples and found this: This is a nice example of Junit5 + Grpc |
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 😄): 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:GrpcCleanupRule
, so thatGrpcTestExtension
and the JUnit 4 rule share as much code as possible.The text was updated successfully, but these errors were encountered: