Skip to content

Tests cannot be launched #1481

Closed
Closed

Description

Added by Sheng Chen (@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.

Activity

  1. mishi321 commented on Sep 1, 2022

    @mishi321

    image
    image

    The same to you, the log file is here

  2. kaipaysen commented on Sep 1, 2022

    @kaipaysen

    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

  3. jdneo commented on Sep 1, 2022

    @jdneo
  4. added this to the 0.37.1 milestone on Sep 1, 2022
  5. jdneo commented on Sep 1, 2022

    @jdneo
    Member

    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.

  6. kaipaysen commented on Sep 1, 2022

    @kaipaysen

    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.

  7. pcantrell commented on Sep 1, 2022

    @pcantrell

    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
  8. pcantrell commented on Sep 1, 2022

    @pcantrell

    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?

  9. lucidfrontier45 commented on Sep 2, 2022

    @lucidfrontier45
    Author

    Sheng Chen (@jdneo)

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

  10. jdneo commented on Sep 2, 2022

    @jdneo
    Member

    Paul Cantrell (@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

  11. jdneo commented on Sep 2, 2022

    @jdneo
    Member

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

  12. pcantrell commented on Sep 2, 2022

    @pcantrell

    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?

  13. pcantrell commented on Sep 2, 2022

    @pcantrell

    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?

  14. jdneo commented on Sep 2, 2022

    @jdneo
    Member
  15. pcantrell commented on Sep 2, 2022

    @pcantrell

    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.

  16. jdneo commented on Aug 5, 2024

    @jdneo
    Member

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions