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

Migrate JUnit 3 tests to JUnit 4 #33

Open
basil opened this issue Aug 18, 2023 · 5 comments
Open

Migrate JUnit 3 tests to JUnit 4 #33

basil opened this issue Aug 18, 2023 · 5 comments
Labels
recipe Requests for new automated code changes

Comments

@basil
Copy link
Contributor

basil commented Aug 18, 2023

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 timtebeek added the recipe Requests for new automated code changes label Aug 18, 2023
@timtebeek timtebeek moved this to Recipes Wanted in OpenRewrite Aug 18, 2023
@timtebeek
Copy link
Contributor

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
Copy link
Contributor Author

basil commented Aug 22, 2023

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
Copy link
Collaborator

sghill commented Aug 22, 2023

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
Copy link
Contributor

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
Copy link
Contributor Author

basil commented Aug 23, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
recipe Requests for new automated code changes
Projects
Status: Recipes Wanted
Development

No branches or pull requests

3 participants