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

JUnit 5 support #220

Open
rhusar opened this issue Sep 27, 2024 · 12 comments
Open

JUnit 5 support #220

rhusar opened this issue Sep 27, 2024 · 12 comments

Comments

@rhusar
Copy link
Collaborator

rhusar commented Sep 27, 2024

Investigate state of JUnit 5 support.

@WolfgangHG
Copy link
Contributor

Main problem: the org.jboss.arquillian.warp.impl.testutils.SeparatedClassloaderRunner must be rewritten and converted to an Extension.

@WolfgangHG
Copy link
Contributor

Seems JUnit5 does not support the scenario that a single test is run in a different classloader.
See this issue Introduce extension API for providing a custom ClassLoader, which is closed as the original reporter found a workaround.

In this issue, I found a link to https://junit.org/junit5/docs/snapshot/user-guide/#launcher-api-launcher-interceptors-custom which could be used to change the classloader. But as far as I understand it, this is done for the whole testsuite, while we would need it only for a few tests in the testsuite.

@rhusar Do you have any idea?

@rhusar
Copy link
Collaborator Author

rhusar commented Dec 1, 2024

I am not that versed in JUnit 5 and also only recently we fixed the remaining issues in Arquillian with injection in JUnit 5. Though, for now we could support JUnit 5 with classloader for the whole testsuite and add notes not to combine Warp tests with other tests in a single surefire/failsafe execution. Not ideal, but at least getting started somewhere.

@WolfgangHG
Copy link
Contributor

We could extract all tests that require the SeparatedClassloader approach to an extra project. In the first step, this old project could still be run with JUnit4. What do you think?
If the LauncherInterceptor requires us to do different runs, it would also make it easier to handle "regular" JUnit runs and those special ones.

@rhusar
Copy link
Collaborator Author

rhusar commented Dec 2, 2024

We could extract all tests that require the SeparatedClassloader approach to an extra project. In the first step, this old project could still be run with JUnit4. What do you think? If the LauncherInterceptor requires us to do different runs, it would also make it easier to handle "regular" JUnit runs and those special ones.

We do need to support both JUnit 4 and JUnit 5 within the same project branch since both of those versions are widely used. So that means we might need a new Warp module for JUnit 5 but definitely a new JUnit 5 surefire execution. Perhaps a common module that has the common JUnit classes.

@WolfgangHG
Copy link
Contributor

Maybe I have misunderstanding here, but I think that JUnit is only used in the internal testsuite of warp. All dependencies have scope "test". There is no code of the extension itself that uses JUnit. So a user of the extension should be free to use JUnit4 or JUnit5. Or is our test dependency on JUnit propagated to all clients using the warp BOM?

@rhusar
Copy link
Collaborator Author

rhusar commented Dec 2, 2024

@WolfgangHG You might be right, I have not looked at this yet - the scope of the issue is really 'Investigate state of JUnit 5 support.' - as this is mostly implemented as an ARQ extension, then perhaps it just works? In that case, maybe a smoke test running with JUnit 5 would suffice.

@WolfgangHG
Copy link
Contributor

@rhusar I gave my small test project (still JavaEE8, references Warp 1.1.0) a try and converted it to JUnit 5 - no problems in this simple test.
If you want to take a look: attached is the project: StatelessMaven.zip

The test class is found at "/StatelessMaven-web/src/test/java/de/hsrm/cs/javaee8/statelessmaven/web/test/WarpIT.java".
"StatelessMaven-web/pom.xml" and "StatelessMaven-ejb/pom.xml" both declare JUnit5 dependencies.
The project uses the bom "org.wildfly.bom:wildfly-jakartaee8-with-tools:26.0.0.Final", which provides a dependency on JUnit4. But I hope this does not conflict here.

@WolfgangHG
Copy link
Contributor

@rhusar I tried to convert the test suite to JUnit 5, code can be found in my fork: https://github.com/WolfgangHG/arquillian-extension-warp/tree/junit5
In the first step, I commented all code that uses org.jboss.arquillian.warp.impl.testutils.SeparatedClassloaderRunner.

The projects "ftest" and "jsf-ftest" work again.

But there are several tests in the "impl" project that fail. The reason seems to be that injection does not happen.
Sample: https://github.com/WolfgangHG/arquillian-extension-warp/blob/junit5/impl/src/test/java/org/jboss/arquillian/warp/impl/client/eventbus/TestCommandEventBusLifecycle.java => the injection for fields of arquillian type Event<Before> or Event<After> does not happen, thus they are null. Do you have any idea? The test class is not annotated with the JUnit4 @ArquillianRunner or the JUnit5 @ArquillianExtension.

As you wrote that the scope of this issue is "investigate whether something needs to be done to support JUnit5 on the consumer side" (and my opinion is that it works without changes), I can create a new issue for converting the test suite.

@rhusar
Copy link
Collaborator Author

rhusar commented Dec 11, 2024

@rhusar I tried to convert the test suite to JUnit 5, code can be found in my fork: https://github.com/WolfgangHG/arquillian-extension-warp/tree/junit5 In the first step, I commented all code that uses org.jboss.arquillian.warp.impl.testutils.SeparatedClassloaderRunner.

I am not up to speed why the SeparatedClassloaderRunner is needed especially since there is no javadoc :-) But I can have a look later.

The projects "ftest" and "jsf-ftest" work again.

We can theoretically do these in parts too, i.e. per module.

But there are several tests in the "impl" project that fail. The reason seems to be that injection does not happen. Sample: https://github.com/WolfgangHG/arquillian-extension-warp/blob/junit5/impl/src/test/java/org/jboss/arquillian/warp/impl/client/eventbus/TestCommandEventBusLifecycle.java => the injection for fields of arquillian type Event<Before> or Event<After> does not happen, thus they are null. Do you have any idea? The test class is not annotated with the JUnit4 @ArquillianRunner or the JUnit5 @ArquillianExtension.

There was problem with injecting to methods, but not to fields. I can have a look.

As you wrote that the scope of this issue is "investigate whether something needs to be done to support JUnit5 on the consumer side" (and my opinion is that it works without changes), I can create a new issue for converting the test suite.

OK, that's good news! So the SeparatedClassloaderRunner is part of the project testing infrastructure - not something that users need to do.

We can keep using this issue for the upgrade, if we want to proceed with that.

@WolfgangHG
Copy link
Contributor

Yes, SeparatedClassLoaderRunner is in the "test" path, so I assume it is only used for internal tests and not public api.

My plan is to experiment with the JUnit5 LauncherInterceptor next week, which hopefully is the replacement for SeparatedClassloaderRunner

@WolfgangHG
Copy link
Contributor

The LauncherInterceptor does not seem to work, as it is initialized only once per test suite. I asked a question in the JUnit5 repository: junit-team/junit5#4203

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants