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

VS Code does not recognize junit tests #1692

Open
siddhsql opened this issue May 16, 2024 · 24 comments
Open

VS Code does not recognize junit tests #1692

siddhsql opened this issue May 16, 2024 · 24 comments

Comments

@siddhsql
Copy link

I am following the steps at this page to run Junit5 tests with VS Code and Maven. I have these extensions installed:

image image image

and my pom.xml has:

<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter</artifactId>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.platform</groupId>
    <artifactId>junit-platform-launcher</artifactId>    
    <scope>test</scope>
</dependency>        

I have put my test classes in src/test/java. but VS Code does not detect JUNIT5 tests. the green "lenses" or "buttons" do not show up next to the tests. In one of the logs I could see:

Preview features enabled at an invalid source release level 21, preview can be enabled only at source level 22; code: 2098258
image

and not sure if it is because of this.

related: #470

@siddhsql
Copy link
Author

I did some search and came across mention of a .classpath file. I do not see such file anywhere in my project.

@jdneo
Copy link
Member

jdneo commented May 17, 2024

@siddhsql What if you run Java: Clean Java Language Server Workspace

@siddhsql
Copy link
Author

siddhsql commented May 17, 2024 via email

@jdneo
Copy link
Member

jdneo commented May 23, 2024

Would you mind sharing the project to us?

@siddhsql
Copy link
Author

siddhsql commented May 23, 2024 via email

@jdneo
Copy link
Member

jdneo commented May 24, 2024

If there are .settings, .classpath, .project files located under your project folder.

Please try to close your vscode, remove the above three files and open your vscode.

@siddhsql
Copy link
Author

siddhsql commented May 24, 2024 via email

@diegoxxc14
Copy link

Hi, I solved this problem in JAVA PROJECTS, Clean Workspace. Then the green buttons are displayed in tests.
image

@siddhsql
Copy link
Author

siddhsql commented May 30, 2024 via email

@jdneo
Copy link
Member

jdneo commented May 30, 2024

@siddhsql Is your problem resolved now?

@jdneo
Copy link
Member

jdneo commented May 30, 2024

There is an undergoing effort about support running test in gradle build server: microsoft/build-server-for-gradle#144

Once Once it's done, I'll check how to integrate that into the test runner extension.

@aisong
Copy link

aisong commented May 30, 2024

@jdneo 我遇到了同样的问题。

执行mvn test-compile -f 可以编译成功。但是在vscode里面找不到测试类。
更加有问题的是,ide似乎不识别test下面的java类,语法错误不会提示。

source action:
WX20240530-141142@2x

testing:
WX20240530-141226@2x

清除目录、clear workspace都重复了很多次,都不解决问题。

能麻烦看下可能是什么问题导致?

@jdneo
Copy link
Member

jdneo commented May 30, 2024

@aisong Could you share a sample project for your issue?

@aisong
Copy link

aisong commented May 30, 2024

@aisong Could you share a sample project for your issue?
@jdneo
业务系统的代码,不好直接发这里呀。🥲

@aisong
Copy link

aisong commented May 30, 2024

我觉得是test目录的识别有问题,没有被正确识别为java sources。

虽然classpath的配置是正确的:
WX20240530-150118@2x

但因为某种原因,ide没有把src/test/java识别为源文件。

查看执行文件,里面只有classes,没有包含test-classes:
WX20240530-150636@2x

@jdneo
Copy link
Member

jdneo commented May 30, 2024

@aisong Have you set java.import.maven.disableTestClasspathFlag

@aisong
Copy link

aisong commented May 30, 2024

@aisong Have you set java.import.maven.disableTestClasspathFlag

not set.

settings:

{
"java.configuration.maven.globalSettings": "/Users/ddxx/dev/maven/apache-maven-3.8.2/conf/settings.xml",
"redhat.telemetry.enabled": false,
"java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx1G -Xms100m -javaagent:"/Users/ddxx/.vscode/extensions/vscjava.vscode-lombok-1.0.1/server/lombok.jar"",
"java.configuration.runtimes": [
{
"name": "JavaSE-17",
"path": "/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home",
// "path": "/Library/Java/JavaVirtualMachines/jdk1.8.0_341.jdk/Contents/Home"
}
],
"java.autobuild.enabled": false,
"terminal.integrated.env.osx": {
"FIG_NEW_SESSION": "1"
},
"workbench.colorTheme": "Default Light Modern",
"codeium.enableConfig": {
"*": true
},
"editor.minimap.enabled": false,
"sonarlint.rules": {

    "Web:ItemTagNotWithinContainerTagCheck": {
        "level": "off"
    },
    "Web:ImgWithoutAltCheck": {
        "level": "off"
    }
},
"sonarlint.output.showVerboseLogs": true,
"sonarlint.focusOnNewCode": true,
"eslint.lintTask.enable": true,
"sonarlint.output.showAnalyzerLogs": true,
"[vue]": {
    "editor.defaultFormatter": "Vue.volar"
},
"sonarlint.connectedMode.project": {},
"sonarlint.connectedMode.connections.sonarqube": [],
"maven.terminal.customEnv": [],
"sonarlint.pathToNodeExecutable": "/Users/ddxx/Dev/DevEnvs/node/node-v18.20.2-darwin-arm64/bin/node",
"editor.stickyScroll.enabled": false,
"java.editor.reloadChangedSources": "auto"

}

@siddhsql
Copy link
Author

no my problem is not solved. i don't use gradle. i am using maven with junit 5. thanks.

@siddhsql
Copy link
Author

siddhsql commented May 30, 2024

this is an unrelated question but does anyone know where does VS Code store the compiled classes? there is a target folder but its meant for use by Maven. Does VS Code overwrite the files in that folder with its compiled code? and is it possible to designate a different folder for vs code so that it does not interfere with maven?

@jdneo
Copy link
Member

jdneo commented May 31, 2024

Does VS Code overwrite the files in that folder with its compiled code?

Yes

is it possible to designate a different folder for vs code so that it does not interfere with maven?

This is a known issue: redhat-developer/vscode-java#314

@aisong
Copy link

aisong commented May 31, 2024

@jdneo 我终于找到我这里的问题出在哪里。但不知道为什么会这样。

在我的pom中引入了一个本地仓库的依赖,如果去掉它,ide会正常,如果引入它就会出现问题。
我打开了trace日志,截取了当在pom中引入这个依赖后出现的错误日志,请见附件。
vscode-java.log

能否从日志中判断出具体是什么问题?

@jdneo
Copy link
Member

jdneo commented May 31, 2024

@aisong, thank you! Tracked at #1693. Will investigate.

@aisong
Copy link

aisong commented May 31, 2024

@aisong, thank you! Tracked at #1693. Will investigate.

好的。看起来是读取依赖的信息时有报错。是依赖包中的文件缺失了什么必要信息么。还没找到解决办法。

@siddhsql
Copy link
Author

redhat-developer/vscode-java#314

this seems like a serious issue to me and am surprised its not fixed even after 7 years.

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

No branches or pull requests

4 participants