Skip to content

Conversation

@strangelookingnerd
Copy link
Contributor

This PR aims to migrate all tests to JUnit5. Changes include:

  • Migrate annotations and imports
  • Migrate assertions
  • Remove public visibility for test classes and methods
  • Minor clean up

I am well aware that this is a quite large changeset however I hope that there is still interest in this PR and it will be reviewed.
If there are any questions, please do not hesitate to ping me.

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests that demonstrate the feature works or the issue is fixed

* Migrate annotations and imports
* Migrate assertions
* Remove public visibility for test classes and methods
* Minor code cleanup
@strangelookingnerd strangelookingnerd requested a review from a team as a code owner September 9, 2025 11:15
Copy link
Member

@alecharp alecharp left a comment

Choose a reason for hiding this comment

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

I globally have no problem with the content of the pull request but I have a few questions:

  • is it strictly required to remove the public from test methods / classes for the migration? Same for the removal of throws declaration in method signature.
  • why rename some of the JenkinsRule from j to r?

Even if those changes are not problematic, it makes the review unnecessarily longer.
It also makes this pull request not only be about JUnit 4 to 5 migration, but about general cleanups.

@alecharp
Copy link
Member

For now, the build is not passing and I think it's related to jenkins-infra/helpdesk#4814.
mvn verify passes, mvn javadoc:javadoc is not.

@strangelookingnerd
Copy link
Contributor Author

is it strictly required to remove the public from test methods / classes for the migration? Same for the removal of throws declaration in method signature.

Reducing the visibility is not required, however a recommended best practice by the framework. In my opinion this brings only advantages e.g. uncovering undesirable dependencies between test classes as well as having cleaner code. In production code you would also want to reduce the visibility where possible and not declare everything public. The same should apply to tests.

Removing the throws declaration is partly done by the migration tool e.g. in cases where @Test(expected = SomeException.class) is replaced by assertThrows. Overall this also helps to clean up the implementations. In my opinion test should either declare throws Exception or nothing at all. This greatly helps in writing clean code that does not prompt hundreds and thousand of warnings in the IDE.

why rename some of the JenkinsRule from j to r?

As some of the migration is still done manually I have some templates to copy & paste or search & replace. The goal is mainly consistency across the test classes.

Even if those changes are not problematic, it makes the review unnecessarily longer. It also makes this pull request not only be about JUnit 4 to 5 migration, but about general cleanups.

Understandable, yet I think that by following the boy scout rule during these migrations that produce a big change set in either way I can help to improve code quality and therefore maintainability of test code. In my experience test code is oftentimes neglected when it comes to having coding standards for a project. That being said, I always try that these migrations do not only replace A with B but also improve the overall project. Adding trivial clean-ups - mostly things my IDE does recommend - is a low hanging fruit.

@Rule
public JenkinsSessionRule r = new JenkinsSessionRule();
@RegisterExtension
private final JenkinsSessionExtension extension = new JenkinsSessionExtension();
Copy link
Member

Choose a reason for hiding this comment

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

NIT: extension as a variable name is not so helpful (yes r is not either and that would probably been better as jenkinsSession) but I find extension slightly worse due to the Jenkins Extension infra so it becomes a little unclear when used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants