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

Can't run or debug JUnit 5 from secondary class

Open ZhengJun003 opened this issue 6 years ago • 18 comments

Environment:

OS: Windows JDK: 8/12 Java Extensions:

  • Language Support for Java(TM) by Red Hat: 0.52.0
  • Debugger for Java: 0.23.0
  • Java Test Runner: 0.21.0

Steps to reproduce:

  1. Open the JUnit5 project in VSCode: https://github.com/ZhengJun003/junit5-samples/tree/testrunner
  2. Run MyFastTestIT and TestTemplateI in the test explorer

Result:

image

image


Added by @jdneo ❗️Solution for those people who cannot run JUnit 5 from the Invisible project(dependency managed in lib folder)

ZhengJun003 avatar Oct 29 '19 08:10 ZhengJun003

Java file's name and class name must be the same, otherwise, maven will skip these cases

ZhengJun003 avatar Oct 29 '19 09:10 ZhengJun003

So it turns out that this is an Eclipse side bug. It will happen when running a class name which is different from the compilation unit name.

I'll reopen it until we fix it in the upstream.

See: https://bugs.eclipse.org/bugs/show_bug.cgi?id=529722#c1

jdneo avatar Oct 30 '19 01:10 jdneo

Hi, I'm having a similar issue. When I try to run tests in my project, I receive the same 'Error: Failed to parse the JUnit launch arguments'. It's for a University project, so I can't use Maven or Gradle, so my project set-up is the 'invisible' type.

What's strange is that I had a similar project of the same layout that I managed to run tests on (Oct 14th), which now no longer works, and gives the same error.

Github link -> here

Environment;

  • Debugger for Java 0.23.0
  • Java Test Runner 0.21.0
  • Language Support 0.52.0

How to repro;

  1. Open project in VSCode.
  2. Open test runner and attempt to run.

I have a feeling I'm missing something really stupid, I hope you can help!

Update (3/11/19): Rolling back to Java Test Runner 0.20.0 fixed the issue! It must be something with the new version.

geist-2501 avatar Nov 02 '19 13:11 geist-2501

@geist-2501, please download the "junit-platform-console-standalone-1.5.2" jar in your project's lib folder.

image

ZhengJun003 avatar Nov 04 '19 01:11 ZhengJun003

@ZhengJun003 Thanks for getting back! I've downloaded the same junit-platform-console-standalone-1.5.2.jar, which has got it closer to working, but now I see a different error message upon runnnig a test: ErrorMessage What changed from 0.20.0 to 0.21.0 that means it now requires the standalone?

geist-2501 avatar Nov 05 '19 15:11 geist-2501

@geist-2501 This seems to a VS Code bug. According to: https://github.com/microsoft/vscode-go/issues/2831#issuecomment-544271725

Would you mind to try it in the latest VS Code Insider?

The changes we made from 0.20.0 to 0.21.0 is to use the Eclipse's JUnit runner instead of our own runners. So the jars in the classpath has been changed.

jdneo avatar Nov 06 '19 01:11 jdneo

@jdneo Yep, just tried it with the latest insiders version and it worked! Thanks!

geist-2501 avatar Nov 06 '19 14:11 geist-2501

It took me a while to find this issue, as I had this problem without using a "secondary class". Downgraded to 20.0 and it works perfectly again.

When will this be fixed in the non-insiders version of VSCode?

OneBigOwnage avatar Nov 10 '19 14:11 OneBigOwnage

@OneBigOwnage VS Code team released 1.40.0 recently. Is this problem still occur in 1.40.0 on your side?

jdneo avatar Nov 11 '19 02:11 jdneo

Hi, I'm having a similar issue. When I try to run tests in my project, I receive the same 'Error: Failed to parse the JUnit launch arguments'. It's for a University project, so I can't use Maven or Gradle, so my project set-up is the 'invisible' type.

What's strange is that I had a similar project of the same layout that I managed to run tests on (Oct 14th), which now no longer works, and gives the same error.

Github link -> here

Environment;

* Debugger for Java 0.23.0

* Java Test Runner 0.21.0

* Language Support 0.52.0

How to repro;

1. Open project in VSCode.

2. Open test runner and attempt to run.

I have a feeling I'm missing something really stupid, I hope you can help!

Update (3/11/19): Rolling back to Java Test Runner 0.20.0 fixed the issue! It must be something with the new version.

I had the same exact issue as you. I am working on a university project, too, and had the following error when running JUnit tests: "Error: Failed to parse the JUnit launch arguments." (VS Code v1.40.0, JUnit Test Runner v0.21.0)

So, I tried your suggestion of rolling back the extension, and JUnit tests run perfectly on VS Code v1.40.0 with JUnit Test Runner v0.20.0. Thank you!

rajkundu avatar Nov 11 '19 03:11 rajkundu

@rajkundu Is it working on VS Code 1.40.0 with Test Runner 0.21.0?

jdneo avatar Nov 11 '19 04:11 jdneo

@jdneo @rajkundu Using VS Code 1.40.0 and Test Runner 0.21.0 works for me now, as long as I have the Junit Standalone Console .jar in a lib folder

geist-2501 avatar Nov 11 '19 10:11 geist-2501

Ok so here is the solution for those people who cannot run JUnit 5 from the Invisible project(dependency managed in lib folder):

  1. Update VS Code to 1.40.0
  2. Update Test Runner to 0.21.0
  3. Have the Junit Standalone Console jar in a lib folder

Note: You may still cannot run JUnit 5 test if your class name is not the same as the Java file. This is a bug from the upstream Eclipse side.

jdneo avatar Nov 11 '19 12:11 jdneo

@jdneo Thanks that works!

vwxyzjn avatar Nov 19 '19 21:11 vwxyzjn

Had the same problem, read this rolled back to v0.20.0 and it worked. I have last version of vscode and class names equal file names. Didn't try having the console jar in a lib folder. I'm using Maven. Don't want to save jars in source control.

moinessim avatar Nov 20 '19 00:11 moinessim

@moinessim Have you tried this solution?

jdneo avatar Nov 20 '19 00:11 jdneo

@moinessim Have you tried this solution?

Hi @jdneo, I tried the following, but had the same error message. Adding the Junit Standalone Console jar:

  • in a lib folder in the project root directory.
  • in a lib folder next to the test class.
  • in the pom.xml as a Maven dependency with test scope.

moinessim avatar Feb 27 '20 21:02 moinessim