最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

visual studio code - SOLVED - Using JUnit with VSCode throws error: "java.lang.NoClassDefFoundError: orgjunitrunnermani

programmeradmin3浏览0评论

SOLVED. I don't know what happened exactly, but I uninstalled and reinstalled Java (JDK and JRE, most up-to-date versions), and then everything started working.

I'm trying to use JUnit to test with VSCode. I've checked all the extensions, imports, tested versions 4 and 5, and I always get the error java.lang.NoClassDefFoundError: org/junit/SomeClass

When testing with JUnit Jupyter, specifically, VSCode returns the error java.lang.NoClassDefFoundError: org/junit/runner/manipulation/Filter in the debug console, while the test results tab shows The test run did not record any output. (probably the tests don't get executed, because of the error).

I've tried running through all the paths that VSCode provides, running all the tests, just one, and I always get the same error.

As you can see, my project is very simple (just for testing), and has a standard structure.

To make sure I wasn't doing anything wrong, I created a class to run the tests manually (TestRunner.java), and when I ran it, everything went perfectly. It is important to say that I created this class after receiving the errors, so it is not interfering.

import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;

public class TestRunner {
    public static void main() {
        Result result = JUnitCore.runClasses(TesteCalculadora.class);
        int count;
        String msg;
        long time = result.getRunTime();

        System.out.println("\n\nRESULTADO DOS TESTES");
        System.out.println("Tempo: " + time + " ms");

        if (result.wasSuccessful()) {
            count = result.getRunCount();
            if (count == 1)
                msg = count + " teste executado com sucesso";
            else
                msg = count + " testes executados com sucesso";

        } else {
            count = result.getFailureCount();
            if (count == 1)
                msg = count + " teste falhou";
            else
                msg = count + " testes falharam";
        }

        System.out.println(msg);

        for (Failure failure : result.getFailures()) {
            System.out.println(failure.toString());
        }

    }
}

This returns, as expected:

RESULTADO DOS TESTES
Tempo: 6 ms
2 testes executados com sucesso

Here is the full error that VSCode returns:

java.lang.NoClassDefFoundError: org/junit/runner/manipulation/Filter
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:383)
    at java.base/java.lang.Class.forName(Class.java:376)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadTestLoaderClass(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.createRawTestLoader(RemoteTestRunner.java:372)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.createLoader(RemoteTestRunner.java:367)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.defaultInit(RemoteTestRunner.java:311)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.init(RemoteTestRunner.java:226)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)
Caused by: java.lang.ClassNotFoundException: org.junit.runner.manipulation.Filter
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    ... 9 more

I'm not using any package and dependency manager, such as maven or gradle. I've tried installing, uninstalling and restoring factory settings for several extensions, but nothing seems to solve the problem.

I tried several solutions that I found on this forum and I was also unsuccessful.

I tried running the tests through the IDE interface. Note that VSCode recognizes the tests perfectly, and places all the indicators and markings correctly.

But when I click on any of the locations that should run the tests, I get the error I mentioned.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论