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

Tests cannot be launched #1481

Closed
lucidfrontier45 opened this issue Sep 1, 2022 · 15 comments · Fixed by #1482
Closed

Tests cannot be launched #1481

lucidfrontier45 opened this issue Sep 1, 2022 · 15 comments · Fixed by #1482
Labels
Milestone

Comments

@lucidfrontier45
Copy link

lucidfrontier45 commented Sep 1, 2022

Added by @jdneo:

check #1481 (comment) for the workaround.

0.37.1 has been released, the problem should be gone with the latest version.


Environment

System : Windows10, WSL2, Debian 11
JDK: OpenJDK 64-Bit Server VM (build 17.0.4+8-Debian-1deb11u1)
Gradle: 7.4.2
VSCode: v1.70.2
redhat.java: v1.10.0
vscjava.vscode-java-test: v0.37.2022083002
vscjava.vscode-java-debug: v0.43.0

Symptom

Test cannot be launched. The notification in the right bottom shows Run Tests: Resolving launch configuration forever

image

How to reproduce

  1. Create an Application project with gradle init .
  2. Open the project folder with VSCode
  3. Open Testing in the side panel.
  4. right click appHasAGreeting() and choose Run Test.

Notes

  1. Running the main of the App class from VSCode works fine.
  2. Running gradle test works fine.
@mishi321
Copy link

mishi321 commented Sep 1, 2022

image
image

The same to you, the log file is here

@kaipaysen
Copy link

Same here.. stuck on "Resolving launch configurations".

System : Mac OS
JDK: OpenJDK Runtime Environment (build 17.0.1+12-39)
Gradle: 7.4.2
Maven: 3.8.5
redhat.java: v1.10.0
vscjava.vscode-java-test: v0.37.0
vscjava.vscode-java-debug: v0.43.0

@jdneo

This comment was marked as resolved.

@jdneo jdneo added the bug label Sep 1, 2022
@jdneo jdneo added this to the 0.37.1 milestone Sep 1, 2022
@jdneo jdneo pinned this issue Sep 1, 2022
@jdneo
Copy link
Member

jdneo commented Sep 1, 2022

For anyone encountered this issue, please install vscode-java-test-0.37.2022090109.vsix.zip to see if the problem got fixed and let me know if it's possible.

I'll do some verification as well. If everything is fine, I'll plan a hotfix release tomorrow.

@kaipaysen
Copy link

For anyone encountered this issue, please install vscode-java-test-0.37.2022090109.vsix.zip to see if the problem got fixed and let me know if it's possible.

I'll do some verification as well. If everything is fine, I'll plan a hotfix release tomorrow.

Great, works on my machine. Thank you very much.

@pcantrell
Copy link

pcantrell commented Sep 1, 2022

Encountering this bug as well — along with the ~50 students in a Java-based course for whom this bug is their introduction to both Java and VS Code. 😬

I tried installing the vsix fix attached above, and got this when trying to run tests:

java.lang.NoClassDefFoundError: org/junit/platform/commons/util/ClassNamePatternFilterUtils
    at org.junit.platform.launcher.core.LauncherFactory.loadAndFilterTestExecutionListeners(LauncherFactory.java:191)
    at org.junit.platform.launcher.core.LauncherFactory.registerTestExecutionListeners(LauncherFactory.java:179)
    at org.junit.platform.launcher.core.LauncherFactory.createDefaultLauncher(LauncherFactory.java:137)
    at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:125)
    at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:109)
    at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.<init>(JUnit5TestLoader.java:37)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) NativeConstructorAccessorImpl.java:77
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) DelegatingConstructorAccessorImpl.java:45
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) Constructor.java:499
    at java.base/java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128) ReflectAccess.java:128
    at java.base/jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:347) ReflectionFactory.java:347
    at java.base/java.lang.Class.newInstance(Class.java:645) Class.java:645
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.createRawTestLoader(RemoteTestRunner.java:371)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.createLoader(RemoteTestRunner.java:366)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.defaultInit(RemoteTestRunner.java:310)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.init(RemoteTestRunner.java:225)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
Caused by: java.lang.ClassNotFoundException: org.junit.platform.commons.util.ClassNamePatternFilterUtils
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) BuiltinClassLoader.java:641
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ClassLoaders.java:188
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520) ClassLoader.java:520
    ... 18 more

Downgrading both the Language Support for Java and Test Runner for Java extensions to the previous release fixes the issue for me:

  • Language Support for Java → 1.9.0
  • Test Runner for Java → 0.36.0

@pcantrell
Copy link

Confirmed error from vsix occurs even after completely uninstalling all Java and Gradle extensions, then doing a clean install.

I installed the vsix using:

code --install-extension vscode-java-test-0.37.2022090109.vsix

Is that the correct method?

@lucidfrontier45
Copy link
Author

@jdneo

Thank you for the fix. I confirmed vscode-java-test-0.37.2022090109.vsix.zip fixed the problem.

@jdneo
Copy link
Member

jdneo commented Sep 2, 2022

@pcantrell This is because we upgrade the bundled junit jupiter version, which has a breaking change start from 1.7.0.

What you need to do is add the dependency org.junit.platform:junit-platform-commons to your project.

See: https://stackoverflow.com/questions/61801256/exception-in-thread-main-java-lang-noclassdeffounderror-org-junit-platform-co

@jdneo
Copy link
Member

jdneo commented Sep 2, 2022

0.37.1 has been released, the problem should be gone with the latest version.

@pcantrell
Copy link

This is because we upgrade the bundled junit jupiter version, which has a breaking change start from 1.7.0.

The build.gradle in the project in question pins Jupiter to an older version:

dependencies {
    testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter', version: '5.6.+'
}

Shouldn’t this prevent that problem? Does the VS Code test runner simply ignore the JUnit version specified in the project file?

@pcantrell
Copy link

Replying to myself: No, I see from experimentation that pinning to an old version of JUnit Jupier in fact causes the problem. Simply updating the Jupiter version number to 5.9.+ fixes the problem, without having to add the junit-platform-commons dependency.

It seems like a bug that vscode-java-test can’t run tests for projects that specify older JUnit versions. After all, the point of specifying a version is precisely to avoid future breakages like this. Should I file that as a new issue?

@jdneo
Copy link
Member

jdneo commented Sep 2, 2022

@pcantrell Please check: https://bugs.eclipse.org/bugs/show_bug.cgi?id=569860.

To fix this issue, we need to provide delegate to Gradle

@pcantrell
Copy link

Thanks for the explanation. This comment echoes my thoughts quite closely. This does seem like a fundamental philosophical problem.

Fortunately I can simply upgrade JUnit in the projects in question, but at the very least, better diagnostics here would be useful.

@jdneo
Copy link
Member

jdneo commented Aug 5, 2024

The Gradle Test Delegation (both run and debug) has supported now.

To use this feature, you need to install the latest Test Runner for Java and Gradle for Java extension.

To delegate the tests to Gradle, you can set the default testing profile in Testing explorer:
image
image

If you do not want to change the default testing profile, you can trigger an one-time execution via:
image
image

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

Successfully merging a pull request may close this issue.

5 participants