vscode-java-test icon indicating copy to clipboard operation
vscode-java-test copied to clipboard

Maven project : Java test classes should override main classes in classpath

Open mrhydejc opened this issue 2 years ago • 1 comments

When running a test with maven surefire, the test classes override the main classes.

My project contains : src/main/java/AsyncConfig.java src/test/java/AsyncConfig.java

When running a test with maven, the classpath contains : src/test/java/AsyncConfig.java and succeed When running a test with VSCode test runner,, the classpath contains : src/main/java/AsyncConfig.java and failed

Is there a maven test runner for vscode ? Or a way to fix this classpath issue ?

mrhydejc avatar Jan 04 '23 13:01 mrhydejc

This is an upstream issue caused by: https://bugs.eclipse.org/bugs/show_bug.cgi?id=498288

So far it's not allowed to contain same type name in different source sets.

jdneo avatar Jan 05 '23 00:01 jdneo

Hi @mrhydejc, I'm an AI Support assistant here to help with your issue. While the team reviews your request, I wanted to provide some possible tips and documentation that might help you in the meantime.

Suggestions to address the classpath ordering in VS Code’s Java Test Runner:

  • There’s no dedicated “Maven test runner” in the Java Test extension; it relies on the Java Language Server’s classpath, which currently merges test and main outputs and picks main classes first.

  • Workaround: opening the test class in the editor can refresh diagnostics and sometimes correct the classpath at runtime (see below).

High-confidence references:

  • Issue: Feature request to use separate output folders for main vs test • Problem: VS Code plugin puts both main & test classes in the same output folder, so test classes don’t override main ones • Status: Open feature request • URL: https://github.com/redhat-developer/vscode-java/issues/2312

  • Issue: Overridden class in test package causes “type is already defined” error • Problem: Classes with the same name in src/main and src/test lead to errors; opening the test file in the editor clears the error • Workaround: open the test file before running to refresh the classpath • URL: https://github.com/redhat-developer/vscode-java/issues/1432

Other references with low confidence

Click to expand

• (no additional relevant issues)

The team will respond to your issue shortly. I hope these suggestions are helpful in the meantime. If this comment helped you, please give it a 👍. If the suggestion was not helpful or incorrect, please give it a 👎. Your feedback helps us improve!

github-actions[bot] avatar Nov 12 '25 15:11 github-actions[bot]