Skip to content

Migrate tests to JUnit5 (core / jenkins / 3) #10578

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

Merged

Conversation

strangelookingnerd
Copy link
Contributor

@strangelookingnerd strangelookingnerd commented Apr 22, 2025

This PR aims to migrate all tests in core (jenkins package) to JUnit5. Changes include:

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

Other, releated PR: #10559 #10576 #10577 #10578 #10579 #10580 #10581 #10582

Why this is a good change:

  • JUnit 5 is the modern standard: It offers a cleaner and more powerful programming model, better extensibility, and improved support for modern Java features (like lambdas, streams, and optional parameters).
  • Improved test maintainability: JUnit 5’s more expressive annotations and lifecycle management make tests easier to read, write, and debug.
  • Enables use of modern extensions: Migrating paves the way to leverage powerful third-party extensions and tooling (e.g., parameterized tests, dynamic tests, conditional execution).

It is important to notice that this change should not alter the test logic, but bring the project in line with modern best practices and help keeping it future-proof.

There are some exceptions were tests have not been migrated (see the list below). The reasons vary per class, overall it's mostly either some custom JenkinsRule implementations that as of now do not properly work with JUnit5. There are also cases where a migration would simply require too much effort with too much risk of altering a tests intentions.

List of test classes not migrated to JUnit5
  • AbstractItem2Test
  • AgentInboundUrlTest
  • ApiTokenStatsRestartTest
  • ArgumentListBuilder2Test
  • BasicHeaderApiTokenAuthenticatorTest
  • BindTest
  • BootFailureTest
  • BuiltInNodeMigrationRestartTest
  • ClassicPluginStrategyTest
  • CustomClassFilterTest
  • CustomPluginManagerTest
  • DisablePluginCommandTest
  • DoubleLaunchCheckerTest
  • ErrorPageTest
  • ExtensionListListenerTest
  • ExtensionListRjrTest
  • FileParameterValuePersistenceTest
  • HudsonPrivateSecurityRealmFIPSTest
  • InboundAgentTlsTest
  • JNLPLauncherRealTest
  • Jenkins64991Test
  • JenkinsBuildsAndWorkspacesDirectoriesTest
  • JenkinsLocationConfigurationTest
  • JenkinsLogRecordsTest
  • JenkinsManagePermissionTest
  • JenkinsSupportAnnotationsTest
  • JenkinsTest
  • JnlpAccessWithSecuredHudsonTest
  • JnlpProtocol4ProxyHandlerTest
  • JnlpSlaveRestarterInstallerTest
  • LifecycleTest
  • LoadDetachedPluginsTest
  • LoginTest
  • NameRefTest
  • NodeParallelTest
  • NodeProvisionerTest
  • NodesRestartTest
  • OfflineNodeCommandTest
  • OldRemotingAgentTest
  • PluginManagerInstalledGUITest
  • PluginManagerTest
  • ProjectTest
  • ProxyConfigurationManagerGUITest
  • QueueCrashTest
  • QueueRestartTest
  • ResponseTimeMonitorTest
  • ReverseBuildTriggerAfterRestartTest
  • ReverseProxySetupMonitorTest
  • RunActionTest
  • Security218Test
  • Security3430Test
  • Security3501Test
  • Security637Test
  • SecurityContextExecutorServiceTest
  • SetContextClassLoaderTest
  • SetupWizardRestartTest
  • SymbolJenkinsTest
  • UnsupportedRemotingAgentEscapeHatchTest
  • UnsupportedRemotingAgentTest
  • UpdateCenterCustomTest
  • UpdateCenterMigrationTest
  • UserRestartTest
  • UserSeedPropertyRestartTest
  • WebSocketAgentsTest
  • XStream2AnnotationTest

I am well aware that this is a huge 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.

Testing done

Lot's of local testing. Still there are some tests that do not run in my environement (with or without any changes).

Proposed changelog entries

  • Migrate tests to JUnit5

Proposed changelog category

/label internal, tests

Proposed upgrade guidelines

N/A

Submitter checklist

  • The Jira issue, if it exists, is well-described.
  • The changelog entries and upgrade guidelines are appropriate for the audience affected by the change (users or developers, depending on the change) and are in the imperative mood (see examples). Fill in the Proposed upgrade guidelines section only if there are breaking changes or changes that may require extra steps from users during upgrade.
  • There is automated testing or an explanation as to why this change has no tests.
  • New public classes, fields, and methods are annotated with @Restricted or have @since TODO Javadocs, as appropriate.
  • New deprecations are annotated with @Deprecated(since = "TODO") or @Deprecated(forRemoval = true, since = "TODO"), if applicable.
  • New or substantially changed JavaScript is not defined inline and does not call eval to ease future introduction of Content Security Policy (CSP) directives (see documentation).
  • For dependency updates, there are links to external changelogs and, if possible, full differentials.
  • For new APIs and extension points, there is a link to at least one consumer.

Desired reviewers

Anyone really, it's a giant changeset with lots of repetitions.

Before the changes are marked as ready-for-merge:

Maintainer checklist

  • There are at least two (2) approvals for the pull request and no outstanding requests for change.
  • Conversations in the pull request are over, or it is explicit that a reviewer is not blocking the change.
  • Changelog entries in the pull request title and/or Proposed changelog entries are accurate, human-readable, and in the imperative mood.
  • Proper changelog labels are set so that the changelog can be generated automatically.
  • If the change needs additional upgrade steps from users, the upgrade-guide-needed label is set and there is a Proposed upgrade guidelines section in the pull request title (see example).
  • If it would make sense to backport the change to LTS, a Jira issue must exist, be a Bug or Improvement, and be labeled as lts-candidate to be considered (see query).

* Migrate annotations and imports
* Migrate assertions
* Remove public visibility for test classes and methods
* Minor code cleanup
@strangelookingnerd strangelookingnerd force-pushed the migrate_to_junit5_core_3 branch from 1808e41 to c9de96e Compare April 25, 2025 19:08
@github-actions github-actions bot added the unresolved-merge-conflict There is a merge conflict with the target branch. label Apr 30, 2025
Copy link
Contributor

Please take a moment and address the merge conflicts of your pull request. Thanks!

# Conflicts:
#	core/src/test/java/jenkins/model/RunIdMigratorTest.java
@github-actions github-actions bot removed the unresolved-merge-conflict There is a merge conflict with the target branch. label May 5, 2025
@NotMyFault NotMyFault requested a review from a team May 28, 2025 15:20
Copy link
Member

@timja timja left a comment

Choose a reason for hiding this comment

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

/label ready-for-merge


This PR is now ready for merge, after ~24 hours, we will merge it if there's no negative feedback.

Thanks!

@comment-ops-bot comment-ops-bot bot added the ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback label May 28, 2025
@NotMyFault NotMyFault merged commit 95b0e64 into jenkinsci:master May 29, 2025
18 checks passed
@MarkEWaite MarkEWaite added the skip-changelog Should not be shown in the changelog label May 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback skip-changelog Should not be shown in the changelog tests This PR adds/removes/updates test cases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants