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

Add recipe for migrating Arquillian tests from JUnit 4 to JUnit 5. #652

Closed
jamezp opened this issue Dec 20, 2024 · 3 comments · Fixed by #654
Closed

Add recipe for migrating Arquillian tests from JUnit 4 to JUnit 5. #652

jamezp opened this issue Dec 20, 2024 · 3 comments · Fixed by #654
Labels
recipe Recipe request

Comments

@jamezp
Copy link
Contributor

jamezp commented Dec 20, 2024

What problem are you trying to solve?

Migrating JUnit 4 Arquillian tests to JUnit 5.

What precondition(s) should be checked before applying this recipe?

None that I'm aware of.

Describe the situation before applying the recipe

@RunWith(Arquillian.class)
class A {
    @Test
    void test() {
        // do test
    }
}

Describe the situation after applying the recipe

@ExtendWith(ArquillianExtension.class)
class A {
    @Test
    void test() {
        // do test
    }
}

Have you considered any alternatives or workarounds?

Any additional context

One difference in the best practices for the JUnit 4 to JUnit 5 migration is changing the scope of classes and methods. In some cases these tests are ran in a container. I'm not sure if this should be part of the org.openrewrite.java.testing.junit5.JUnit5BestPractices recipe or not yet.

Are you interested in contributing this recipe to OpenRewrite?

I would like to contribute or help contribute the fix. What I currently have is:

type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.testing.junit5.ArquillianJUnit4ToArquillianJunit5
displayName: Use Arquillian JUnit 5 Extension
description: Migrates Arquillian `@RunWith` `Arquillian` to the JUnit Jupiter `@ExtendWith` `ArquillianExtension`.
tags:
  - testing
  - junit
  - arquillian
recipeList:
  - org.openrewrite.java.testing.junit5.RunnerToExtension:
      runners:
        - org.jboss.arquillian.junit.Arquillian
      extension: org.jboss.arquillian.junit5.ArquillianExtension
  - org.openrewrite.java.ChangePackage:
      oldPackageName: org.jboss.arquillian.junit
      newPackageName: org.jboss.arquillian.junit5
      recursive: true
  - org.openrewrite.java.dependencies.ChangeDependency:
      oldGroupId: org.jboss.arquillian.junit
      oldArtifactId: arquillian-junit-container
      newGroupId: org.jboss.arquillian.junit5
      newArtifactId: arquillian-junit5-container
@jamezp
Copy link
Contributor Author

jamezp commented Dec 20, 2024

I'm seeing some strange things when testing. I'm not seeing the org.junit.jupiter:junit-jupiter dependency added to the POM. However, I see the Arquillian dependencies being replaceed.

[WARNING] Changes have been made to container-bootable/pom.xml by:
[WARNING]     org.openrewrite.java.testing.junit5.JUnit4to5Migration
[WARNING]         org.openrewrite.java.dependencies.RemoveDependency: {groupId=junit, artifactId=junit}
[WARNING]         org.openrewrite.java.testing.junit5.ArquillianJUnit4ToArquillianJunit5
[WARNING]             org.openrewrite.java.dependencies.ChangeDependency: {oldGroupId=org.jboss.arquillian.junit, oldArtifactId=arquillian-junit-container, newGroupId=org.jboss.arquillian.junit5, newArtifactId=arquillian-junit5-container}

@timtebeek timtebeek moved this to Recipes Wanted in OpenRewrite Dec 20, 2024
@timtebeek timtebeek added the recipe Recipe request label Dec 20, 2024
@timtebeek
Copy link
Contributor

hi @jamezp ! That looks like a decent start already, thanks! Would you mind pushing that up to a draft PR such that I can help troubleshoot the issue you're having?

@jamezp
Copy link
Contributor Author

jamezp commented Dec 20, 2024

Thank you @timtebeek, done #654. It's definitely not complete and I know there are some bugs, but for the most part it seems to be working.

I've been testing on https://github.com/wildfly/wildfly-arquillian. This project as some other issues I need to look into like it uses some @RunWith(Suite.class), but that could be something that just manually needs to be fixed which is not a big deal.

@github-project-automation github-project-automation bot moved this from Recipes Wanted to Done in OpenRewrite Dec 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
recipe Recipe request
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants