quarkus icon indicating copy to clipboard operation
quarkus copied to clipboard

Unable to run QuarkusTests in Eclipse since Quarkus 3.22

Open manofthepeace opened this issue 6 months ago • 2 comments

Describe the bug

In Eclipse IDE, Right click on a file Run As-> Junit fails with the followiing;

java.lang.RuntimeException: Internal error. The test class class org.acme.GreetingResourceTest should have been loaded with a QuarkusClassLoader, but instead it was loaded with jdk.internal.loader.ClassLoaders$AppClassLoader@63c12fb0. This is caused by the FacadeClassLoader not correctly identifying this class as a QuarkusTest.
	at io.quarkus.test.junit.QuarkusTestExtension.getClassLoaderFromTestClass(QuarkusTestExtension.java:337)
	at io.quarkus.test.junit.QuarkusTestExtension.ensureStarted(QuarkusTestExtension.java:631)
	at io.quarkus.test.junit.QuarkusTestExtension.beforeAll(QuarkusTestExtension.java:712)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)

Runnin a single test from a @QuarkuTest works

Expected behavior

Running a full file works

Actual behavior

Exceptions happens

How to Reproduce?

reproduder: code.quarkus.io and download the default project

Steps to reproduce 1 - Import the maven project into eclipse 2- right click on the test class in the package explorer, or on the class name within the editor 3- Run As-> Junit Test

Output of uname -a or ver

Darwin Kernel Version 24.4.0

Output of java -version

Temurin-21.0.7+6

Quarkus version or git rev

22.0.1

Build tool (ie. output of mvnw --version or gradlew --version)

mvn 3.9.9

Additional information

Running a single test seem to work ok.

manofthepeace avatar May 01 '25 19:05 manofthepeace

cc @holly-cummins

manofthepeace avatar May 01 '25 20:05 manofthepeace

Thanks for the report! Will have a look. It's interesting (and unexpected) that it works for single tests, but not whole files.

holly-cummins avatar May 01 '25 20:05 holly-cummins

@gsmet, @mkouba have you guys by any chance noticed this?

geoand avatar May 02 '25 05:05 geoand

Also reported on Zulip: https://quarkusio.zulipchat.com/#narrow/channel/187030-users/topic/Test.20fails.20on.20Eclipse.20IDE.20with.20Quarks.203.2E22.2E1/near/515665452

holly-cummins avatar May 02 '25 08:05 holly-cummins

If I do run as on the org.acme package I get this:

Image

so normal test passes, but IT fails with

java.lang.IllegalStateException: Unable to locate the artifact metadata file created that must be created by Quarkus in order to run integration tests. Make sure this test is run after the Quarkus artifact is built from your build tool.
	at io.quarkus.test.junit.IntegrationTestUtil.readQuarkusArtifactProperties(IntegrationTestUtil.java:409)
	at io.quarkus.test.junit.QuarkusIntegrationTestExtension.ensureStarted(QuarkusIntegrationTestExtension.java:141)
	at io.quarkus.test.junit.QuarkusIntegrationTestExtension.beforeAll(QuarkusIntegrationTestExtension.java:127)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)

if I run the test from the .java file it has same error.

But if I run the greetingtest (non IT) individually I get:

java.lang.RuntimeException: Internal error. The test class class org.acme.GreetingResourceTest should have been loaded with a QuarkusClassLoader, but instead it was loaded with jdk.internal.loader.ClassLoaders$AppClassLoader@251a69d7. This is caused by the FacadeClassLoader not correctly identifying this class as a QuarkusTest.
	at io.quarkus.test.junit.QuarkusTestExtension.getClassLoaderFromTestClass(QuarkusTestExtension.java:337)
	at io.quarkus.test.junit.QuarkusTestExtension.ensureStarted(QuarkusTestExtension.java:631)
	at io.quarkus.test.junit.QuarkusTestExtension.beforeAll(QuarkusTestExtension.java:712)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)


so for me it does NOT work when running individually - but tests does work when I run per package, but not when IT.

maxandersen avatar May 02 '25 09:05 maxandersen

can confirm running single method or via package normal test works - IT fails always.

if I run the suite class it fails.

maxandersen avatar May 02 '25 09:05 maxandersen

and can also confirm if i downgrade to 3.20 then test class works no matter what but IT class fails for same reasons as in 3.22 so i Ireckon that is not a new issue.

maxandersen avatar May 02 '25 09:05 maxandersen

Ah, I had a feeling the IT issue might have been there before, but I didn't want to say until I checked! I've raised https://github.com/quarkusio/quarkus/issues/47661 for the IT case.

holly-cummins avatar May 02 '25 10:05 holly-cummins

I've had a look at this, and it's going to be hard to fix without knowing the internals of Eclipse's JUnit support. It looks like in this particular scenario, test discovery is happening outside any of the normal JUnit mechanisms, and at a different stage in the start lifecycle.

But I have another workaround. If, after running the test, you right click in the failed test in the JUnit panel and click 'Run', you can run the whole test.

Image

holly-cummins avatar May 02 '25 15:05 holly-cummins

in case its useful here is how it is run (found in properties on debug run process):

/Users/manderse/.sdkman/candidates/java/17.0.9-graalce/bin/java -XX:+ShowCodeDetailsInExceptionMessages -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:50566 -ea -Djava.util.logging.manager=org.jboss.logmanager.LogManager -javaagent:/Users/manderse/eclipse/jee-2025-03/Eclipse.app/Contents/Eclipse/configuration/org.eclipse.osgi/436/0/.cp/lib/javaagent-shaded.jar -Dfile.encoding=UTF-8 -Dstdout.encoding=UTF-8 -Dstderr.encoding=UTF-8 -classpath <massive classpath> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner -version 3 -port 50565 -testLoaderClass org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader -loaderpluginname org.eclipse.jdt.junit5.runtime -classNames org.acme.GreetingResourceTest

maxandersen avatar May 02 '25 16:05 maxandersen

Ooh, thanks @maxandersen! While you have it handy, do you think you could gather the same commands for the 'run individual method' scenario and the 'run from the Run window' scenario?

holly-cummins avatar May 02 '25 16:05 holly-cummins

I don't know if I should create another issue, but the same thing happens with VSCode. Runnin @QuarkusTest test class throws class loader error, individual tests work.

java.lang.RuntimeException: Internal error. The test class class datareceiver.RestRequestTest should have been loaded with a QuarkusClassLoader, but instead it was loaded with jdk.internal.loader.ClassLoaders$AppClassLoader@639fee48. This is caused by the FacadeClassLoader not correctly identifying this class as a QuarkusTest.
 at io.quarkus.test.junit.QuarkusTestExtension.getClassLoaderFromTestClass([QuarkusTestExtension.java:337](vscode-file://vscode-app/.../resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
 at io.quarkus.test.junit.QuarkusTestExtension.ensureStarted([QuarkusTestExtension.java:631](vscode-file://vscode-app/.../resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
 at io.quarkus.test.junit.QuarkusTestExtension.beforeAll([QuarkusTestExtension.java:712](vscode-file://vscode-app/.../app/out/vs/code/electron-sandbox/workbench/workbench.html))
 at java.base/java.util.ArrayList.forEach([ArrayList.java:1596](vscode-file://vscode-app/.../resources/app/out/vs/code/electron-sandbox/workbench/workbench.html)) 

Tomnivore avatar May 02 '25 20:05 Tomnivore

@gsmet, @mkouba have you guys by any chance noticed this?

I usually do not run @QuarkuTests from the Eclipse IDE. The Eclipse's JUnit support never really worked for anything but simple unit tests 🤷.

mkouba avatar May 05 '25 06:05 mkouba

I suppose a lot of people could run a test from an IDE for a single class to debug it without launch a mvn command that is slower for sure. And it seams that Visual Studio Code is broken in the same way.

psini avatar May 05 '25 16:05 psini

I get the error when running tests during ./gradlew quarkusDev

<====2025-05-07 15:24:37,632 INFO  [io.qua.test] (Quarkus Terminal Reader) Test output enabled
Starting tests
Press [e] to edit command line args (currently ''), [r] to re-run, [h] for more options>
Press [e] to edit command line args (currently ''), [r] to re-run, [o] Toggle test output, [h] for more options>
Running tests for the first time1s]
Press [e] to edit command line args (currently ''), [h] for more options>
Press [e] to edit command line args (currently ''), [o] Toggle test output, [h] for more options>

2025-05-07 15:24:38,911 ERROR [io.qua.test] (Test runner thread) Internal error running tests: java.lang.RuntimeException: java.util.NoSuchElementException: No value present
        at io.quarkus.deployment.dev.testing.JunitTestRunner.prepare(JunitTestRunner.java:447)
        at io.quarkus.deployment.dev.testing.ModuleTestRunner.prepare(ModuleTestRunner.java:83)
        at io.quarkus.deployment.dev.testing.TestSupport.runInternal(TestSupport.java:430)
        at io.quarkus.deployment.dev.testing.TestSupport$3.run(TestSupport.java:389)
        at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: java.util.NoSuchElementException: No value present
        at java.base/java.util.Optional.get(Optional.java:143)
        at io.quarkus.deployment.dev.testing.JunitTestRunner.discoverTestClasses(JunitTestRunner.java:716)
        at io.quarkus.deployment.dev.testing.JunitTestRunner.prepare(JunitTestRunner.java:166)
        ... 4 more

kesslerd avatar May 07 '25 13:05 kesslerd

@kesslerd, I think what you're seeing is a different issue, since it's gradle, not Eclipse. Could you raise a new issue with some more details about what's in your application, and ideally a reproducer?

holly-cummins avatar May 09 '25 14:05 holly-cummins

We encountered the same issue in Intellij and in our gitlab pipeline. I raised a question regards this issue in the zulip chat as well #users > Test do not work anymore after upgrade from 3.21.4 to 3.22.1

u6f6o avatar May 13 '25 11:05 u6f6o

See also https://stackoverflow.com/questions/79654040/quarkus-could-not-read-configuration-while-evaluating-whether-to-run-class/.

holly-cummins avatar Jun 05 '25 08:06 holly-cummins

I have a new workaround. Editing the run configuration for a test class and adding a unique id with the name of that class gets things working, for just that class. For example, -uniqueId [engine:junit-jupiter]/[class:org.acme.GreetingResourceTest]:

Image

That means we have the following workarounds:

  • Run individual test methods
  • Run whole packages
  • Run a test class normally, and then when the class fails, right click on the class in the JUnit window and run it.
  • Manually edit the run configuration and add a unique id. This simulates the 're-run failing test' path that's working

holly-cummins avatar Jun 05 '25 16:06 holly-cummins

I have raised https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/2257, and a fix https://github.com/eclipse-jdt/eclipse.jdt.ui/pull/2258. This fix should be in Eclipse 4.37. We're unlikely to be able to work around this on the Quarkus side (except with the workarounds mentioned above).

What I will do is update the error message to mention the workarounds.

holly-cummins avatar Jun 05 '25 17:06 holly-cummins

and can also confirm if i downgrade to 3.20 then test class works no matter what but IT class fails for same reasons as in 3.22 so i Ireckon that is not a new issue.

I've raised https://github.com/quarkusio/quarkus/issues/48273 for the IT issue. It reproduces in all IDEs.

holly-cummins avatar Jun 06 '25 14:06 holly-cummins

I'm still seeing a separate issue with integration tests in Eclipse (beyond just #48273), so I'll raise a new issue to cover that.

holly-cummins avatar Jun 09 '25 16:06 holly-cummins