简体   繁体   中英

vscode Maven Java Project Test are running successfully using mvn command but failing when run from the "Testing" explorer

When I use maven to run tests with this command it works fine:

mvn test -f "c:\path\to\pom.xml"

But when I run the test using the "Testing Explorer" in vscode, it fails with this error:

java.lang.NoClassDefFoundError: path/to/package/ClassName
 at path.to.package.ClassName.TestName(TestFileName.java:15)
Caused by: java.lang.ClassNotFoundException: path.to.package.ClassName
 at java.net.URLClassLoader.findClass(URLClassLoader.java:387)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
 at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
 ... 24 more

It appears that the test doesn't find the required dependencies when it runs. However, the required dependencies for the test method are available and I can see them in other folders under the project but not under the target folder.

Perhaps the question is how to specify the class path when running the tests from the vscode Testing Explorer view.

You can try to create a customized test launch configuration in the settings. There you can specify the classpaths to be appended. See: https://github.com/microsoft/vscode-java-test/wiki/Run-with-Configuration

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM