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

How to use Arquillian JUnit 4 runner with jakarta.inject #670

Open
cortlepp opened this issue Jan 27, 2025 · 1 comment
Open

How to use Arquillian JUnit 4 runner with jakarta.inject #670

cortlepp opened this issue Jan 27, 2025 · 1 comment

Comments

@cortlepp
Copy link

I am currently trying to migrate some tests that use the Arquillian JUnit 4 runner in conjunction with javax.inject fields to use the jakarta.inject namespace. When doing so Arquillian now no longer detects the fields I want it to inject.

I have not really found any official documentation for this, only a blogpost which seems to suggest that I need to migrate to JUnit 5 and the Arquillian JUnit5 extension in order to use jakarta.inject. Is this true, and is there official documentation for this?

The project I am doing this for is apache artemis-cdi-client, this is the specific test I am currently trying to fix.

Any help/pointers would be greatly appreciated.

@jamezp
Copy link
Collaborator

jamezp commented Jan 27, 2025

FWIW if you want to automate the migration there is a OpenRewrite recipe for that.

<plugin>
    <groupId>org.openrewrite.maven</groupId>
    <artifactId>rewrite-maven-plugin</artifactId>
    <version>6.0.0</version>
    <configuration>
        <activeRecipes>
            <recipe>org.openrewrite.java.testing.junit5.JUnit4to5Migration</recipe>
            <recipe>org.openrewrite.java.testing.junit5.CleanupAssertions</recipe>
            <recipe>org.openrewrite.java.testing.cleanup.AssertLiteralBooleanToFailRecipe</recipe>
            <recipe>org.openrewrite.java.testing.junit5.AddParameterizedTestAnnotation</recipe>
            <recipe>org.openrewrite.java.testing.junit5.RemoveTryCatchFailBlocks</recipe>
            <recipe>org.openrewrite.java.testing.junit5.LifecycleNonPrivate</recipe>
            <recipe>org.openrewrite.java.testing.junit5.AssertThrowsOnLastStatement</recipe>
            <recipe>org.openrewrite.java.testing.arquillian.ArquillianJUnit4ToArquillianJUnit5</recipe>
        </activeRecipes>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>org.openrewrite.recipe</groupId>
            <artifactId>rewrite-testing-frameworks</artifactId>
            <version>3.0.0</version>
        </dependency>
    </dependencies>
</plugin>

That said, it should work to use jakarta.inject. What Arquillian Adapter are you using? From the project it looks like either Weld or OpenBeans. You'll want to make sure you're using the newest version of those as well and ensure they support Jakarta EE 9+.

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

No branches or pull requests

2 participants