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
297 stars 129 forks source link

Can't run or debug JUnit 5 from secondary class #859

Open ZhengJun003 opened 5 years ago

ZhengJun003 commented 5 years ago

Environment:

OS: Windows JDK: 8/12 Java Extensions:

Steps to reproduce:

  1. Open the JUnit5 project in VSCode: https://github.com/ZhengJun003/junit5-samples/tree/testrunner
  2. Run MyFastTestITand TestTemplateIin 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 commented 5 years ago

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

jdneo commented 5 years ago

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

geist-2501 commented 5 years ago

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;

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.

ZhengJun003 commented 5 years ago

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

image

geist-2501 commented 5 years ago

@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?

jdneo commented 5 years ago

@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.

geist-2501 commented 5 years ago

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

OneBigOwnage commented 5 years ago

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?

jdneo commented 5 years ago

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

rajkundu commented 5 years ago

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!

jdneo commented 5 years ago

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

geist-2501 commented 5 years ago

@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

jdneo commented 5 years ago

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.

vwxyzjn commented 4 years ago

@jdneo Thanks that works!

moinessim commented 4 years ago

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.

jdneo commented 4 years ago

@moinessim Have you tried this solution?

moinessim commented 4 years ago

@moinessim Have you tried this solution?

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