Skip to content

Conversation

@strangelookingnerd
Copy link
Contributor

@strangelookingnerd strangelookingnerd commented Jul 16, 2025

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 July 16, 2025 12:28
@daniel-beck
Copy link
Member

Could you provide a motivation for this change? What is the benefit of this, especially given it's not even complete and needs amending in the future?

@strangelookingnerd
Copy link
Contributor Author

Could you provide a motivation for this change? What is the benefit of this, especially given it's not even complete and needs amending in the future?

JUnit4 is no longer actively maintained. JUnit5 has taken over as its successor and is now widely considered the modern standard. JUnit6 is expected to be released later this year.

Although JUnit4 still functions well, remains compatible with most tools and frameworks, and currently has no known vulnerabilities, there's no guarantee this will remain the case in the future.

If JUnit were a typical runtime dependency, upgrading to a newer version would seem natural over time. In my opinion, this logic should apply equally to test dependencies. Yet there seems to be a common perception among developers that once a test is written, it should never need to be touched again. I believe that's a misconception. Test code is just as important to maintain as production code. That's why I'm doing my part to help projects modernize their test suites and ensure they're maintainable in the long run by adopting up-to-date tools and best practices.

As you noted, the migration to JUnit5 isn’t complete - and that’s perfectly fine. It’s a starting point. It can serve as a blueprint for writing new tests and help lower the barrier of entry for contributors, both to this project and similar ones. The migrated tests are fully functional, as are those still using JUnit4.

From a technical standpoint, there isn’t a major immediate benefit in this project’s specific context. While JUnit5 offers improvements beyond just aesthetic changes, they may not be critical here. Usage, syntax, and performance are roughly equivalent. However, I do anticipate that over time, more tooling and frameworks will drop support or stop adding features for JUnit4 - making it increasingly harder to justify sticking with it.

@daniel-beck
Copy link
Member

daniel-beck commented Jul 25, 2025

Thanks for this explanation and your perspective.

Any ETA for when the migration could be completed? I'd rather not run the risk of making it more work when having to migrate another test to/from RJR because of some random BOM change not involving this plugin (#136 / jenkinsci/bom#1911 (comment)) (even thought admittedly miniscule).

@strangelookingnerd
Copy link
Contributor Author

Thanks for this explanation and your perspective.

Any ETA for when the migration could be completed? I'd rather not run the risk of making it more work when having to migrate another test to/from RJR because of some random BOM change not involving this plugin (#136 / jenkinsci/bom#1911 (comment)) (even thought admittedly miniscule).

Understandable. I requested a review on jenkinsci/jenkins-test-harness#988 just now - let's see what comes out of it.

@strangelookingnerd strangelookingnerd marked this pull request as ready for review August 8, 2025 17:47
@daniel-beck
Copy link
Member

daniel-beck commented Aug 13, 2025

@strangelookingnerd WDYT about this? (Not yet requesting its inclusion, just generally.) Would prevent accidental regressions of this change. Might this be something for the parent pom, enabled via property perhaps?

diff --git a/pom.xml b/pom.xml
index 8ce7fdd..abece2d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -114,4 +114,38 @@
       <url>https://repo.jenkins-ci.org/public/</url>
     </pluginRepository>
   </pluginRepositories>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-enforcer-plugin</artifactId>
+        <dependencies>
+          <dependency>
+            <groupId>de.skuzzle.enforcer</groupId>
+            <artifactId>restrict-imports-enforcer-rule</artifactId>
+            <version>2.6.1</version>
+          </dependency>
+        </dependencies>
+        <executions>
+          <execution>
+            <id>check-junit-imports</id>
+            <goals>
+              <goal>enforce</goal>
+            </goals>
+            <phase>process-sources</phase>
+            <configuration>
+              <rules>
+                <RestrictImports>
+                  <reason>Use JUnit 5 (org.junit.jupiter.*)</reason>
+                  <bannedImport>org.junit.**</bannedImport>
+                  <allowedImport>org.junit.jupiter.**</allowedImport>
+                </RestrictImports>
+              </rules>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
 </project>

@strangelookingnerd
Copy link
Contributor Author

@strangelookingnerd WDYT about this? (Not yet requesting its inclusion, just generally.) Would prevent accidental regressions of this change. Might this be something for the parent pom, enabled via property perhaps?

For projects that have already migrated (fully) this would be a great addition to prevent regressions.
Integrating it into the parent would need to be opt-in like spotless.check.skip.

@daniel-beck
Copy link
Member

Integrating it into the parent would need to be opt-in like spotless.check.skip.

Agree, that's what I meant by

enabled via property perhaps

@daniel-beck daniel-beck merged commit 443bd0f into jenkinsci:main Aug 17, 2025
17 checks passed
<jenkins.baseline>2.479</jenkins.baseline>
<jenkins.version>${jenkins.baseline}.3</jenkins.version>
<spotless.check.skip>false</spotless.check.skip>
<ban-junit4-imports.skip>true</ban-junit4-imports.skip>
Copy link
Member

Choose a reason for hiding this comment

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

🤦

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