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

chore: use Junit5 in java core #2754

Merged
merged 48 commits into from May 16, 2024
Merged

chore: use Junit5 in java core #2754

merged 48 commits into from May 16, 2024

Conversation

JoeWang1127
Copy link
Collaborator

@JoeWang1127 JoeWang1127 commented May 8, 2024

Fix #2726.

BaseSerializationTest will not migrate to Junit 5 because downstream libraries, e.g., java-logging, are extending this class and these libraries still use Junit 4. Migrating this class to Junit 5 will cause test failures in downstream libraries.

@product-auto-label product-auto-label bot added the size: m Pull request size is medium. label May 8, 2024
@JoeWang1127 JoeWang1127 requested a review from a team as a code owner May 10, 2024 13:18
</dependency>
<!-- Test dependencies -->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this line before junit-bom?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@blakeli0
Copy link
Collaborator

Can you please add more info regarding the skipped test classes? Maybe add comments to BaseSerializationTest and PR description?

Comment on lines 42 to 46
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.10.2</version>
<type>pom</type>
<scope>import</scope>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be missing some context about dependency management with java-core and/or test jars, but I would have assumed this version would be been defined in pom-parent or shared-deps instead of having to declare it here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think declare a test dependency in java-core is fine since it allows other modules to use different testing framework.

That being said, we can declare test dependencies in a centralized place, e.g., third-party dependency. However, this should be a separate task.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@suztomo Do you have any suggestions of what's the best way to manage junit 5 dependencies?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid declaring junit bom in the dependencyManagement section of pom.xml files that would go to the Libraries BOM, such as the pom-parent or gapic-generator-java-bom. That would control library users' junit usage.

Third-party-dependencies is good but java-core, I believe, does not import it.

How about declaring the JUnit version as a property, not dependencyManagement section, in the pom-parent?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@suztomo thanks for the suggestion.

Copy link
Contributor

@lqiu96 lqiu96 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@JoeWang1127 JoeWang1127 requested a review from blakeli0 May 10, 2024 18:38
<artifactId>junit-bom</artifactId>
<version>${junit.version}</version>
<type>pom</type>
<scope>import</scope>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per @suztomo's suggestion, I don't think we want to import junit bom in java-core, as I think it would go into shared-dependencies. So I think we should declare those three test dependencies individually and manage the version through the parent pom, is that correct @suztomo ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to import junit bom in java-core, as I think it would go into shared-dependencies

java-core it not imported by the shared dependencies BOM.

Having JUnit in third-party-dependencies is a good place. Because third-party-dependencies BOM does not go to the Libraries BOM.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

java-core it not imported by the shared dependencies BOM.

I think it is included in the first-party-dependencies, am I missing something?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

java-core imports shared dependencies in parant pom, why this doesn't cause a circular dependency?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is included in the first-party-dependencies, am I missing something?

Suppose a project, A, imports shared dependencies, then A doesn't need to declare java-core version (imported from google-cloud-core-bom), but A needs to declare junit version since import BOM doesn't work for transitive dependencies.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

am I missing something?

Importing a BOM and declaring dependencies are different. For a BOM, only imported BOMs matters.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, first-party-dependencies imports google-cloud-core bom, which also imports junit bom, so junit bom would ends up in libraries bom?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, first-party-dependencies imports google-cloud-core bom, which also imports junit bom, so junit bom would ends up in libraries bom?

Actually, junit bom will not end up in libraries bom since only artifacts declared in google-cloud-core-bom will end up in libraries bom. In this case, they are google-cloud-core, google-cloud-core-grpc, google-cloud-core-http.

junit, however, is a transitive dependency, which does not appear in google-cloud-core-bom.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I think we should declare those three test dependencies individually and manage the version through the parent pom

I think use junit-bom is better because junit-platform-launcher has a different version than junit-jupiter-engine and junit-vintage-engine.

Copy link

sonarcloud bot commented May 16, 2024

Quality Gate Passed Quality Gate passed for 'gapic-generator-java-root'

Issues
16 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link

sonarcloud bot commented May 16, 2024

Quality Gate Passed Quality Gate passed for 'java_showcase_integration_tests'

Issues
16 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@JoeWang1127 JoeWang1127 enabled auto-merge (squash) May 16, 2024 18:57
@JoeWang1127 JoeWang1127 merged commit c2ba1d4 into main May 16, 2024
51 checks passed
@JoeWang1127 JoeWang1127 deleted the chore/junit5-java-core branch May 16, 2024 18:58
lqiu96 pushed a commit that referenced this pull request May 16, 2024
Fix #2726.

`BaseSerializationTest` will not migrate to Junit 5 because downstream
libraries, e.g., java-logging, are extending this class and these
libraries still use Junit 4. Migrating this class to Junit 5 will cause
test failures in downstream libraries.
lqiu96 pushed a commit that referenced this pull request May 22, 2024
Fix #2726.

`BaseSerializationTest` will not migrate to Junit 5 because downstream
libraries, e.g., java-logging, are extending this class and these
libraries still use Junit 4. Migrating this class to Junit 5 will cause
test failures in downstream libraries.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: l Pull request size is large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate Junit 4 to Junit 5: java-core
4 participants