Unable to run test case, do not display debug run button on the left column of junit file or test method
rqwsa opened this issue · 11 comments
Java extension plugin,Extension Pack for java :
Debugger for java
Test Runner for java
Project Manager for java
Maven for java
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
Where is the problem ?
Could you share a sample project for this issue?
Okay, Git address :
https://github.com/rqwsa/testdemo/tree/master
git clone --branch master https://github.com/rqwsa/testdemo.git
There are something wrong I found in the sample project:
- 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>
"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 usejava.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:
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.
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>
@kirkzhangtech Yes the extension does not support JUnit 3.x
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
If the eclipse related configuration is deleted, the run button will not be displayed
It relies heavily on eclipse and hopes to improve on maven
@Iscrdr I can confirm the extension supports Maven project. Could you share your maven project?
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
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.
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