Vscode-java-test: Java test runner did not run test and always shows skipped.

Created on 16 Jun 2018  ·  52Comments  ·  Source: microsoft/vscode-java-test

image
When I try to use this function to test on JUnit, the tests are not actually running and all of my cases are just skipped.
image

These test are running in eclipse without any problem. Pls help

Most helpful comment

Thanks @MsaasAPI. Your comment above really helped:

However, after _restarting VS Code_, it is working now. I suspect it has something to do with launch.test.json file it automatically created upon re-launch.

⚠️ NOTE: As of Version: 1.30.2, launch.test.json is now depricated.

I looked at Java Test Runner Config to see latest implementation.

I was using:

Gradle 2.14.1
JUnit 4.5.0

After looking at documentation I got it to work with following steps:

  1. updated JUnit to 4.8
  2. Add "java.test.defaultConfig": "default" in my settings.json file
  3. Re-compile in Gradle
  4. Execute palette command: Java: Clean the Java language server workspace
    4.1. Choose Restart and delete

This is working for me. Hope this helps others as well.
Thanks everyone!

All 52 comments

I am also facing this issue for all my tests

same issue here

@ckfrank @kzmuhia @senekis could you help share the code snippets that repro the case or the test log during that period? thanks.

The log has the message below
Error: command 'java.test.explorer.run' not found

@kzmuhia did you trigger the test from test explorer? Could you try to triger the test run from codelens, something like below:
image
Does it also meet this problem?

Yes it does, I actually got the message while using codelens

Then it seems to have nothing to do with the log message above. @kzmuhia could you help share a code snippet that repro the case?

Hi,

I went to the link https://code.visualstudio.com/docs/java/java-tutorial
Pulled the code from git as per the instruction
Attempted to run the test under HelloControllerTest-> getHello

I am currently using the preview version of vs-code, although I got the same results on the regular one

Here this problem was solved changed pattern name to *Test.java.

@kzmuhia I cannot repro your case, could you help paste your test output? You can open test output window by opening command palette, and choose Java: show test output.
image

@lramosduarte It isn't necessary to follow the pattern *Test.java as long as you follow junit annotation. Are you using some plugin like maven-surefire-plugin which could filter specific tests by config?

@ansyral below is the output
Error occurred: No test found to run.@@<{"name":"testReporterAttached"}>

@lramosduarte It isn't necessary to follow the pattern *Test.java as long as you follow junit annotation. Are you using some plugin like maven-surefire-plugin which could filter specific tests by config?

I am to use default config.

sample pom.xml:

<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.21.0</version>
    <dependencies>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-surefire-provider</artifactId>
            <version>1.2.0</version>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.2.0</version>
        </dependency>
    </dependencies>
</plugin>

same issue cause hamcrest-all-1.3.jar miss .
java:show test output
java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing

@MyselfJar java.lang.NoClassDefFoundError seems to be classpath issue, could you open another issue to track it? A small codesnippet and steps to repro your issue would be appreciated. Thanks.

@lramosduarte could you help share a sample code to repro your issue? Thanks.

@lramosduarte could you help share a sample code to repro your issue? Thanks.

i had created 1 scenario to test this problem, and if i give name file *Test.Java it work.

But if i rename to pattern Test*.java, the runner always skip class TestCase.

Prints:

export

captura de tela de 2018-07-04 10-27-13

Log Runner

{
    "sessionId": "62c4c985-ac47-4f68-9fe7-94f6da311e33",
    "level": "error",
    "message": "Error occurred: No test found to run.",
    "timestamp": "2018-07-04T13:26:36.662Z"
}
{
    "sessionId": "62c4c985-ac47-4f68-9fe7-94f6da311e33",
    "level": "info",
    "message": "@@<{\"name\":\"testReporterAttached\"}>",
    "timestamp": "2018-07-04T13:26:36.664Z"
}
{
    "sessionId": "62c4c985-ac47-4f68-9fe7-94f6da311e33",
    "level": "info",
    "message": "\n",
    "timestamp": "2018-07-04T13:26:36.665Z"
}

Having this issue too

Having the same issue

Same issue. Is the only solution to add a * before each test file name? For me, if I add the * before a test name (ex: UserControllerTests.java --> *UserControllerTests.java), not only does the issue not get fixed, but the file doesn't even show up in the Test Explorer

Same issue here.

Same issue here.

Same issue here.I tried to change the filename to * test.java, but the result was the same.It just always show skipped all test in Test Report.
@Test public void printSome() { System.out.println("test"); }

I updated vscode recently and the problem went away. I'm currently at:

Version: 1.27.2 (system setup)
Commit: f46c4c469d6e6d8c46f268d1553c5dc4b475840f
Date: 2018-09-12T16:17:45.060Z
Electron: 2.0.7
Chrome: 61.0.3163.100
Node.js: 8.9.3
V8: 6.1.534.41
Architecture: x64

I'm running the following on Fedora but still have the issue.

`
Version: 1.28.1

Commit: 3368db6750222d319c851f6d90eb619d886e08f5

Date: 2018-10-11T18:09:20.566Z

Electron: 2.0.9

Chrome: 61.0.3163.100

Node.js: 8.9.3

V8: 6.1.534.41

Architecture: x64

`

Same issue with me:

Version: 1.28.1
Commit: 3368db6750222d319c851f6d90eb619d886e08f5
Date: 2018-10-11T18:09:20.566Z
Electron: 2.0.9
Chrome: 61.0.3163.100
Node.js: 8.9.3
V8: 6.1.534.41
Architecture: x64

Also receiving an error message of "Failed to get the project." in the java_test_runner.log. File found via Java: Open log.
Tests are also showing "Not run" rather than "Skipped".

Same issue here initially...

Version: 1.28.2 (user setup)
Commit: 7f3ce96ff4729c91352ae6def877e59c561f4850
Date: 2018-10-17T00:23:51.859Z
Electron: 2.0.9
Chrome: 61.0.3163.100
Node.js: 8.9.3
V8: 6.1.534.41
Architecture: x64

However, after restarting VS Code, it is working now. I suspect it has something to do with launch.test.json file it automatically created upon re-launch.

{
    "run": {
        "default": "",
        "items": [
            {
                "name": "xxxxxx",
                "projectName": "xxxxxx",
                "workingDirectory": "xxxxxx",
                "args": [],
                "vmargs": [],
                "env": {},
                "preLaunchTask": ""
            }
        ]
    },
    "debug": {
        "default": "",
        "items": [
            {
                "name": "xxxxxx",
                "projectName": "xxxxxx",
                "workingDirectory": "xxxxxx",
                "args": [],
                "vmargs": [],
                "env": {},
                "preLaunchTask": ""
            }
        ]
    }
}

Make sure your test class is public

Same issue, running via CodeLens.
Tests that are initially named *Test succeed in running all tests. These also succeed when attempting to run a single test within the class.
Tests that are named using a different scheme skip all tests, and also skip at the individual test level. Interestingly, renaming these to fit the *Test schema does not fix the skipping issue, even after restarting VSCode.

I had the same problem. All my tests were skipped. They end with Test.java.

Restart did not help.

Workaorund for me was to clean the cache for the project.
To clean cache:

Close vscode.
Delete project folder under C:Users[YOUR_USER]AppDataRoamingCodeUserworkspaceStorage
Start vscode again.

Version: 1.28.2 (system setup)
Commit: 7f3ce96ff4729c91352ae6def877e59c561f4850
Date: 2018-10-17T00:23:51.859Z
Electron: 2.0.9
Chrome: 61.0.3163.100
Node.js: 8.9.3
V8: 6.1.534.41
Architecture: x64

Not sure if that helps, but here's my pom.xml. The test runner is currently working for me, though occasional VS Code restarts is needed if a new @Test annotated method is not detected.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.contoso.misc002</groupId>
  <artifactId>misc002</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>misc002</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.hamcrest</groupId>
      <artifactId>hamcrest-all</artifactId>
      <version>1.3</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <properties>
    <maven.compiler.source>10</maven.compiler.source>
    <maven.compiler.target>10</maven.compiler.target>
  </properties>
</project>
   Version: 1.28.2 (user setup)
   Commit: 7f3ce96ff4729c91352ae6def877e59c561f4850
   Date: 2018-10-17T00:23:51.859Z
   Electron: 2.0.9
   Chrome: 61.0.3163.100
   Node.js: 8.9.3
   V8: 6.1.534.41
   Architecture: x64

Well, in my case I can't get it to work at all. It keeps skipping the tests regardless if I keep the proper naming schema or not. Clearing the cache didn't help either.

This is the error I see in the java_test_runner.log:
{"userTag":false,"level":"info","message":"Error: Could not find or load main class com.microsoft.java.test.runner.JUnitLauncher","timestamp":"2018-11-06T17:22:21.090Z"}
{"userTag":false,"level":"info","message":"n","timestamp":"2018-11-06T17:22:21.090Z"}
{"userTag":false,"error":"Runner exited with code 1.","level":"error","message":"Failed to run tests.","timestamp":"2018-11-06T17:22:21.093Z"}

Where is the classpath set?

@kocic11 Could you check if there is a jar file named com.microsoft.java.test.runner-*.jar under

$HOME\.vscode\extensions\vscjava.vscode-java-test-0.10.0\server?

@jdneo Yes, there are four jar files in the folder $HOME/.vscode/extensions/vscjava.vscode-java-test-0.10.0/server:
com.microsoft.java.test.plugin-0.10.0.jar
com.microsoft.java.test.runner-0.10.0.jar
com.microsoft.java.test.runner.junit5-0.10.0.jar
com.microsoft.java.test.runner.junit5-0.10.0-jar-with-dependencies.jar

This started working all of sudden. I have created a new project and opened it in VS Code (new instance) and the tests are running now.

Facing the same issue as well. Every test I run shows as skipped. If I run the test's thru maven they run fine.
Version: 1.29.1
Commit: bc24f98b5f70467bc689abf41cc5550ca637088e
Date: 2018-11-15T19:07:43.495Z
Electron: 2.0.12
Chrome: 61.0.3163.100
Node.js: 8.9.3
V8: 6.1.534.41
Architecture: x64

I am also seeing the error in java_test_runner.log:

Error: Could not find or load main class com.microsoft.java.test.runner.JUnitLauncher

Also facing similar problem, until I quit vscode completely and restart the project the skip test problem is gone. Looks like vscode is starting some Java server to serve the junit test request and that server has some problem in class loading in the entire session.

{"userTag":false,"error":"Runner exited with code 1.","level":"error","message":"Failed to run tests.","timestamp":"2018-11-21T08:52:49.894Z"}
{"userTag":false,"level":"error","message":"Error occurred: {"name":"error", "attributes":{"message":"Failed to launch Junit", "details":"java.lang.NoClassDefFoundError: org/junit/runner/JUnitCore\n\tat java.lang.ClassLoader.defineClass1(Native Method)\n\tat java.lang.ClassLoader.defineClass(ClassLoader.java:760)\n\tat java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)\n\tat java.net.URLClassLoader.defineClass(URLClassLoader.java:467)\n\tat java.net.URLClassLoader.access$100(URLClassLoader.java:73)\n\tat java.net.URLClassLoader$1.run(URLClassLoader.java:368)\n\tat java.net.URLClassLoader$1.run(URLClassLoader.java:362)\n\tat java.security.AccessController.doPrivileged(Native Method)\n\tat java.net.URLClassLoader.findClass(URLClassLoader.java:361)\n\tat java.lang.ClassLoader.loadClass(ClassLoader.java:424)\n\tat sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)\n\tat java.lang.ClassLoader.loadClass(ClassLoader.java:357)\n\tat com.microsoft.java.test.runner.JUnitLauncher.execute(JUnitLauncher.java:25)\n\tat com.microsoft.java.test.runner.JUnitLauncher.main(JUnitLauncher.java:15)\nCaused by: java.lang.ClassNotFoundException: org.junit.runner.JUnitCore\n\tat java.net.URLClassLoader.findClass(URLClassLoader.java:381)\n\tat java.lang.ClassLoader.loadClass(ClassLoader.java:424)\n\tat sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)\n\tat java.lang.ClassLoader.loadClass(ClassLoader.java:357)\n\t... 14 more\n"}}","timestamp":"2018-11-21T08:52:52.070Z"}
{"userTag":false,"level":"info","message":"@@","timestamp":"2018-11-21T08:52:52.070Z"}

all test always skiped!!! what can I do?

If mvn test runs well, you can try kill vscode and restart, vscode runs
test in a seperate service and that service has problem loading the test
configuration

On Mon, Dec 3, 2018 at 8:02 PM @刘飞 notifications@github.com wrote:

all test always skiped!!! what can I do?


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/Microsoft/vscode-java-test/issues/208#issuecomment-443686989,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABPtWhIAKkYtw6k7whwGqSPrBLUe8Ry3ks5u1RLkgaJpZM4Uqlxe
.

I am also facing the same problem and my java_test_runner.log shows:

{"message":"@@n","level":"info"}

Version info of VS-code:
Version: 1.30.1
Commit: dea8705087adb1b5e5ae1d9123278e178656186a
Date: 2018-12-18T18:07:32.870Z
Electron: 2.0.12
Chrome: 61.0.3163.100
Node.js: 8.9.3
V8: 6.1.534.41
OS: Linux x64 4.15.0-42-generic

Version of Java Test Runner: 0.12.0

Did you try a clean and then rebuild?

For me, that is “mvn clean install”

On Dec 20, 2018, at 5:23 AM, Maarten Joosten notifications@github.com wrote:

I am also facing the same problem and my java_test_runner.log shows:

{"message":"@@n","level":"info"}

Version info of VS-code:
Version: 1.30.1
Commit: dea8705087adb1b5e5ae1d9123278e178656186a
Date: 2018-12-18T18:07:32.870Z
Electron: 2.0.12
Chrome: 61.0.3163.100
Node.js: 8.9.3
V8: 6.1.534.41
OS: Linux x64 4.15.0-42-generic

Version of Java Test Runner: 0.12.0


You are receiving this because you commented.
Reply to this email directly, view it on GitHub https://github.com/Microsoft/vscode-java-test/issues/208#issuecomment-448998279, or mute the thread https://github.com/notifications/unsubscribe-auth/ABwn3P4QbcAMcpO4fCwUlK8uQ9XQDtYlks5u649sgaJpZM4Uqlxe.

@Scott4man Yes, but still got the same result (even after restarting vscode)

@Scott4man Yes, but still got the same result (even after restarting vscode)

You need "ps | grep vscode" and killl all related process. Since service is hosted in a seperate one, which still running even you close vscode.

Some update from my side: I noticed this issue occurs when I run Junit5 tests; Junit4 tests run fine.

@keigezellig Thanks for reporting. Would you mind to create a new issue then?

It might because the Junit 5 is not supported well now.

@jdneo I think #477 is related, although in my case i didn't have a multi-maven project

I had this problem and it turned out the issue was that my code wouldn't compile.

Thanks @MsaasAPI. Your comment above really helped:

However, after _restarting VS Code_, it is working now. I suspect it has something to do with launch.test.json file it automatically created upon re-launch.

⚠️ NOTE: As of Version: 1.30.2, launch.test.json is now depricated.

I looked at Java Test Runner Config to see latest implementation.

I was using:

Gradle 2.14.1
JUnit 4.5.0

After looking at documentation I got it to work with following steps:

  1. updated JUnit to 4.8
  2. Add "java.test.defaultConfig": "default" in my settings.json file
  3. Re-compile in Gradle
  4. Execute palette command: Java: Clean the Java language server workspace
    4.1. Choose Restart and delete

This is working for me. Hope this helps others as well.
Thanks everyone!

@All

I'm closing this issue since the issue description is too generic, and the extension has been changed a lot since this issue was created. For anyone who still meets this problem, please first try the solution that @rrmistry has provided. If you still meet the problem after adopting the solution, Please feel free to create a new issue.

Thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ashoknailwal picture ashoknailwal  ·  8Comments

jbelford picture jbelford  ·  5Comments

Gueka picture Gueka  ·  3Comments

thegabriele97 picture thegabriele97  ·  8Comments

sceee picture sceee  ·  8Comments