quarkus: JUnit Extension is loaded with wrong classloader inside @QuarkusTest
Describe the bug
(Describe the problem clearly and concisely.)
When using an custom JUnit extension the classloader for the extension is different then the classloader for the actual test.
This is only inside @QuarkusTest annotated tests.
Expected behavior (Describe the expected behavior clearly and concisely.) Same classloader as test.
Actual behavior (Describe the actual behavior clearly and concisely.) Different classloader (AppClassLoader vs. Base Runtime Classloader)
To Reproduce Steps to reproduce the behavior:
https://github.com/tkalmar/bug-with-quarkus
org.acme.ExampleResourceTest fails because of the class loading issue
org.acme.StaticProviderTest shows the expected and in my opinion correct behaviour.
Configuration
# Add your application.properties here, if applicable.
Screenshots (If applicable, add screenshots to help explain your problem.)
Environment (please complete the following information):
- Output of
uname -aorver:MINGW64_NT-10.0-18363 XXX 3.1.4-340.x86_64 2020-05-19 12:55 UTC x86_64 Msys - Output of
java -version:openjdk 11.0.7 2020-04-14 LTS - GraalVM version (if different from Java):
- Quarkus version or git rev:
1.6.0.Final - Build tool (ie. output of
mvnw --versionorgradlew --version):Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Additional context (Add any other context about the problem here.)
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 2
- Comments: 38 (26 by maintainers)
Commits related to this issue
- Make sure that test callbacks always work on the proper test method Fixes: #10623 — committed to geoand/quarkus by geoand 4 years ago
- Make sure that test callbacks always work on the proper test method Fixes: #10623 — committed to geoand/quarkus by geoand 4 years ago
- Make sure that test callbacks always work on the proper test method Fixes: #10623 — committed to geoand/quarkus by geoand 4 years ago
- Make sure that test callbacks always work on the proper test method Fixes: #10623 — committed to geoand/quarkus by geoand 4 years ago
- Make sure that test callbacks always work on the proper test method Fixes: #10623 — committed to geoand/quarkus by geoand 4 years ago
- Merge pull request #10675 from geoand/#10623 Make sure that test callbacks always work on the proper test method — committed to quarkusio/quarkus by stuartwdouglas 4 years ago
- Make sure that test callbacks always work on the proper test method Fixes: #10623 — committed to gsmet/quarkus by geoand 4 years ago
Yeah, we could do that as well. Feel free to open an issue and ping me and Stuart. I’m +1 for it, but Stuart might have some good reason for not adding it.
#10675 fixes the annotation lookup issue - essentially was what happening was that
QuarkusTestMethodContextcontained the method from the original class - not the one loaded from the Quarkus ClassLoader.Ok, i extended the reproducer to showcase our workaround. This turns all tests green. This will work for our own extensions for the project but not for extensions we share between projects or which are third-party. Perhaps it is something which can be done by the quarkus magic fairy automatically, disable the JUnit extension and turn it in an Interceptor … So the extension doesn’t need to be aware of quarkus and cdi at all and runs inside the right classloader …
You are right, but this does not change the result. 😉 Thanks for reviewing was a little late.