Skip to content
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

Migrate Junit 4 to Junit 5: gax-java #1611

Closed
blakeli0 opened this issue Apr 6, 2023 · 1 comment · Fixed by #2724
Closed

Migrate Junit 4 to Junit 5: gax-java #1611

blakeli0 opened this issue Apr 6, 2023 · 1 comment · Fixed by #2724
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@blakeli0
Copy link
Collaborator

blakeli0 commented Apr 6, 2023

Junit 5 provides a lot of new features(namely Precise exception handling, RepeatedTest etc.) that could be useful to us, it requires Java 8 to be the minimum runtime version, now that Java 8 is the minimum supported version for GAPIC, we can follow the migration guide to modernize our testing infra.
We can start with all the handwritten code in this repo, and expand to google-cloud-java and eventually handwritten libraries.

@blakeli0 blakeli0 added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. priority: p2 Moderately-important priority. Fix may not be included in next release. labels Apr 6, 2023
@lqiu96
Copy link
Contributor

lqiu96 commented Feb 28, 2024

One additional benefit of JUnit 5 from this implementation: #2485

JUnit 4 doesn't have support for setting Environmental Variables inside tests. JUnit 5 has an extension pack which allows setting and clearing the env vars: https://junit-pioneer.org/docs/environment-variables/

@blakeli0 blakeli0 changed the title Migrate Junit 4 to Junit 5 Migrate Junit 4 to Junit 5: gax-java May 3, 2024
@blakeli0 blakeli0 self-assigned this May 14, 2024
blakeli0 added a commit that referenced this issue May 17, 2024
This PR migrate all unit tests in Gax to Junit 5.

Other than standard direct replacements, some tests need to be rewritten
due to the following scenarios:
- `@Rule` does not exist anymore and there is no direct replacement. We
mostly use it to initialize a Mockito stub, replaced with
`@ExtendWith(MockitoExtension.class)`.
- Some tests were relying on try-catch to assert exceptions, replaced
with `assertThrows`. e.g.
[OperationsClientTest](https://github.com/googleapis/sdk-platform-java/pull/2724/files#diff-4530df761eff0854357165d951e1667d3810a5448ec2aa4b853a6331516cbde0)
- Parameterized tests in
[AbstractRetryingExecutorTest](https://github.com/googleapis/sdk-platform-java/pull/2724/files#diff-9c5f5c1d2fcef6c4164fc0171d01e7020aa7ebb7aa49615cf3743dc89c9b3d1d)

There are a few environment variable tests can be re-written with Junit
5, so we don't need to configure a
[profile](https://github.com/googleapis/sdk-platform-java/blob/main/gax-java/gax/pom.xml#L115-L128)
for it anymore, but they are not in the scope of this PR.

fixes: #1611.
lqiu96 pushed a commit that referenced this issue May 22, 2024
This PR migrate all unit tests in Gax to Junit 5.

Other than standard direct replacements, some tests need to be rewritten
due to the following scenarios:
- `@Rule` does not exist anymore and there is no direct replacement. We
mostly use it to initialize a Mockito stub, replaced with
`@ExtendWith(MockitoExtension.class)`.
- Some tests were relying on try-catch to assert exceptions, replaced
with `assertThrows`. e.g.
[OperationsClientTest](https://github.com/googleapis/sdk-platform-java/pull/2724/files#diff-4530df761eff0854357165d951e1667d3810a5448ec2aa4b853a6331516cbde0)
- Parameterized tests in
[AbstractRetryingExecutorTest](https://github.com/googleapis/sdk-platform-java/pull/2724/files#diff-9c5f5c1d2fcef6c4164fc0171d01e7020aa7ebb7aa49615cf3743dc89c9b3d1d)

There are a few environment variable tests can be re-written with Junit
5, so we don't need to configure a
[profile](https://github.com/googleapis/sdk-platform-java/blob/main/gax-java/gax/pom.xml#L115-L128)
for it anymore, but they are not in the scope of this PR.

fixes: #1611.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants