microsoft / vscode-java-test

Run and debug Java test cases in Visual Studio Code.
https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-test
Other
290 stars 124 forks source link

Unable to run test case, do not display debug run button on the left column of junit file or test method #1665

Closed rqwsa closed 4 months ago

rqwsa commented 5 months ago
UTF-8 21 21 org.junit.jupiter junit-jupiter-api 5.4.2 test org.junit.jupiter junit-jupiter-engine 5.4.2 test

Java extension plugin,Extension Pack for java : Debugger for java Test Runner for java Project Manager for java Maven for java

debug

Unable to run test case, do not display debug run button on the left column of junit file or test method The main method can be debugged and run

debug2

Where is the problem ?

jdneo commented 5 months ago

Could you share a sample project for this issue?

rqwsa commented 4 months ago

Okay, Git address :

https://github.com/rqwsa/testdemo/tree/master

git clone --branch master https://github.com/rqwsa/testdemo.git

jdneo commented 4 months ago

There are something wrong I found in the sample project:

  1. Since this is not a Spring Boot application, to specify the java version,

    <properties>
    <maven.compiler.target>21</maven.compiler.target>
    <maven.compiler.source>21</maven.compiler.source>
    </properties>

    instead of <java.version>21</java.version>

  2. "java.jdt.ls.java.home" is used to specify the JDK to launch the extension itself, it is not related to the project configuration. Because for most of the popular platforms, we put an embedded JRE in the extesnion, so usually there is no need to set this setting. You can use java.configuration.runtimes (a USER level setting) to tell the Java extension all your Java installation paths. For example:

    "java.configuration.runtimes": [
        {
            "name": "JavaSE-21",
            "path": "C:\\foo\\bar\\jdk-21.0.2.13-hotspot"
        }
    ],

After updating the above places, reload VS Code and you should see the test run shortcut button: image

jdneo commented 4 months ago

I'll close the issue since it's not a bug. But the discussion can still continue. Feel free to ask any questions if you have.

kirkzhangtech commented 3 months ago

i hit the same issue , i apply all changes of above , but not work , at the final i update junit version from 3.18 to 4.12 . and now work fine

<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.lab2</groupId>
  <artifactId>lab2-project</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>lab2-project</name>
  <url>http://maven.apache.org</url>
  <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>

  </dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>17</source>
                <target>17</target>
            </configuration>
        </plugin>
    </plugins>
</build>
<properties>
    <maven.compiler.target>17</maven.compiler.target>
    <maven.compiler.source>17</maven.compiler.source>
</properties>
</project>
jdneo commented 3 months ago

@kirkzhangtech Yes the extension does not support JUnit 3.x

Iscrdr commented 3 months ago

The cause of the problem is generally clear. It is developed based on eclipse. I use eclipse to generate the relevant project environment.Classpath, and it can run normally

j

If the eclipse related configuration is deleted, the run button will not be displayed

image

It relies heavily on eclipse and hopes to improve on maven

jdneo commented 3 months ago

@Iscrdr I can confirm the extension supports Maven project. Could you share your maven project?

Iscrdr commented 3 months ago

The @rqwsa's demo: https://github.com/rqwsa/testdemo/tree/master  When I modify the environment (such as adding JVM parameters), the project reloads, and the test doesn't run again.

Other colleagues of mine have also encountered this problem, and the reason has not been found yet. I preliminarily believe that maven and the classpath of the project may be inconsistent in some places after reloading the project.

the strange thing is that after I update the project with eclipse, I come back and use vscode, the junit test, to run the test case normally

jdneo commented 3 months ago

When I modify the environment

How did you modify the jvm args?

And I noticed that the sample project configured "java.jdt.ls.java.home", what if you remove that setting? This setting is used to specify a jre to launch the extension itself. But since we have an embedded jre in the extension, in most cases, there is no need to configure this setting.

Iscrdr commented 3 months ago

I mean, as long as the project reloads, the test can't run,

It's not just changing jvm args : "java.jdt.ls.vmargs": "-XX:+UseParallelGC -Xmx1G -Xms100m -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8" , changing other configurations in other setting.json, manually reload, and the test can't run.

Tip: no tests found in this file  With the eclipse update project, you'll be up and running immediately