openrewrite / rewrite-jenkins

OpenRewrite recipes to continuously modernize Jenkins plugins.
Apache License 2.0
9 stars 8 forks source link

Migrate JUnit 3 tests to JUnit 4 #33

Open basil opened 1 year ago

basil commented 1 year ago

Some plugin tests still extend the JUnit 3 TestCase object. JUnit 4 tests are much more common in Jenkins core and in Jenkins plugins. Migrate the JUnit 3 tests to JUnit 4. See this StackOverflow article that describes the steps to migrate from JUnit 3 to JUnit 4. To identify the sources impacted, search in all project files for patterns like import junit.framework.TestCase or extends TestCase.

timtebeek commented 1 year ago

I think we should already be able to cover most of this through our JUnit 4 & Jupiter recipes: https://docs.openrewrite.org/recipes/java/testing/junit5

The TestCase migration you've mentioned specifically could be handled in https://docs.openrewrite.org/recipes/java/testing/junit5/migratejunittestcase

If there's any missing steps or imperfections we'd love to hear; should be easy to pick up in: https://github.com/openrewrite/rewrite-testing-frameworks

basil commented 1 year ago

The TestCase migration you've mentioned specifically could be handled in https://docs.openrewrite.org/recipes/java/testing/junit5/migratejunittestcase

No, that is for migrating from JUnit 4 to JUnit 5. This ticket is about migrating from JUnit 3 to JUnit 4.

sghill commented 1 year ago

The mentioned recipe does go from a junit.framework.TestCase directly to org.junit.jupiter.api.Test. I guess the question is if jumping to 5 in as few steps as possible is desirable? No right answer of course, this is more the art of change.

timtebeek commented 1 year ago

Yes it's a bit of a leap, and I'll leave that decision up to both of you. Just know that JUnit Jupiter was released in 2017, so I'd lean towards making that leap now, rather than invest effort into a recipe copy that targets JUnit 4 still.

basil commented 1 year ago

JUnit 5 is largely unused in the Jenkins project, so while I am not opposed to trying it out, I am sure there will be some problems. In other words, we would want to roll this out slowly until we gain more experience and confidence with JUnit 5.

In contrast JUnit 4 largely "just works" and is well adopted in the Jenkins project, and there are very few places left still using JUnit 3, so we can confidently and quickly migrate the remaining stragglers to JUnit 4 and roll this change out immediately.