简体   繁体   English

线程“main”中的异常 java.lang.NoSuchMethodError: org.junit.platform.commons.util.ReflectionUtils.getDefaultClassLoader()Ljava/lang/ClassLoader;

[英]Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform.commons.util.ReflectionUtils.getDefaultClassLoader()Ljava/lang/ClassLoader;

I'm trying to run the test with wiremock on Intellij but getting the error .我正在尝试在 Intellij 上使用 wiremock 运行测试,但出现错误。 Could someone please help me with that issue?有人可以帮我解决这个问题吗?

    public class Tests {

    private WireMockServer wireMockServer;

    @Before
    public void setup() {
        wireMockServer = new WireMockServer(8080);
        wireMockServer.start();
        setupStub();
    }

    @After
    public void teardown() {
        wireMockServer.stop();
    }

    public void setupStub() {
        wireMockServer.stubFor(get(urlEqualTo(PEOPLE_PATH))
                .willReturn(aResponse().withHeader("Content-Type", "text/plain")
                        .withStatus(200)
                        .withBodyFile("/Users/denis/Documents/people/autotests/src/test/resources/_files/json/people.json")));
    }

    @Test
    public void testStatusCodePositive() {
        given().
                when().
                get(BASE_URL + PEOPLE_PATH).
                then().
                assertThat().statusCode(200);
    }
}

here is the error that i get: Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform.commons.util.ReflectionUtils.getDefaultClassLoader()Ljava/lang/ClassLoader;这是我得到的错误:线程“main”中的异常 java.lang.NoSuchMethodError: org.junit.platform.commons.util.ReflectionUtils.getDefaultClassLoader()Ljava/lang/ClassLoader; at org.junit.platform.launcher.core.ServiceLoaderTestEngineRegistry.loadTestEngines(ServiceLoaderTestEngineRegistry.java:31) at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:42) at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:43)在 org.junit.platform.launcher.core.ServiceLoaderTestEngineRegistry.loadTestEngines(ServiceLoaderTestEngineRegistry.java:31) 在 org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:42) 在 com.intellij.junit5.JUnit5IdeaTestRunner .startRunnerWithArgs(JUnit5IdeaTestRunner.java:43)

here is my pom.xml这是我的 pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>

   <groupId>com.people.apitest</groupId>
   <artifactId>people-apitest</artifactId>
   <version>1.0-SNAPSHOT</version>

   <dependencies>

      <dependency>
         <groupId>com.github.tomakehurst</groupId>
         <artifactId>wiremock</artifactId>
         <version>2.24.1</version>
      </dependency>

      <dependency>
         <groupId>org.junit.jupiter</groupId>
         <artifactId>junit-jupiter-engine</artifactId>
         <version>5.5.2</version>
         <scope>test</scope>
      </dependency>

      <dependency>
         <groupId>io.rest-assured</groupId>
         <artifactId>rest-assured</artifactId>
         <version>4.1.1</version>
         <scope>test</scope>
      </dependency>

      <dependency>
         <groupId>com.jayway.restassured</groupId>
         <artifactId>json-schema-validator</artifactId>
         <version>2.8.0</version>
      </dependency>
   </dependencies>
</project>

It seems you have a dependency clash between wiremock and junit5.您似乎在wiremock 和junit5 之间存在依赖冲突。 When I look at the wiremock dependencies on mvncentral, it states it uses xmlunit underneath ( https://mvnrepository.com/artifact/com.github.tomakehurst/wiremock/2.26.3 ).当我查看 mvncentral 上的 wiremock 依赖项时,它声明它在下面使用 xmlunit ( https://mvnrepository.com/artifact/com.github.tomakehurst/wiremock/2.26.3 )。

Following that dependency, you can see xmlunit uses Junit4 underneath ( https://mvnrepository.com/artifact/org.xmlunit/xmlunit-core/2.6.2 ).遵循该依赖项,您可以看到 xmlunit 在下面使用 Junit4 ( https://mvnrepository.com/artifact/org.xmlunit/xmlunit-core/2.6.2 )。

I can quite find in which version the 'getDefaultClassloader' method is available from reading the public JUnit APIs.我可以通过阅读公共 JUnit API 找到“getDefaultClassloader”方法在哪个版本中可用。 I suggest you try and remove the dependency on junit5 and use junit4 for your testing, to see if that fixes your classloading issue.我建议您尝试删除对 j​​unit5 的依赖,并使用 junit4 进行测试,看看是否能解决您的类加载问题。

If you are using a dependency manager (mvn, gradle), you can list your effective dependencies using command line or your IDE.如果您正在使用依赖项管理器(mvn、gradle),您可以使用命令行或您的 IDE 列出您的有效依赖项。 If you see clashing versions of junit, investigate on that path.如果您看到 junit 的版本冲突,请在该路径上进行调查。

edit: also, welcome to the infamous "dependency hell"编辑:另外,欢迎来到臭名昭著的“依赖地狱”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 线程“主”中的Spring异常java.lang.NoSuchMethodError:org.springframework.util.ReflectionUtils.clearCache()V - Spring Exception in thread “main” java.lang.NoSuchMethodError: org.springframework.util.ReflectionUtils.clearCache()V java.lang.NoSuchMethodError:org / springframework / util / ReflectionUtils.isPublicStaticFinal(Ljava / lang / reflect / Field;)Z - java.lang.NoSuchMethodError: org/springframework/util/ReflectionUtils.isPublicStaticFinal(Ljava/lang/reflect/Field;)Z 线程“ main”中的异常java.lang.NoSuchMethodError:org.jboss.resteasy.util.CaseInsensitiveMap.add(Ljava / lang / String; Ljava / lang / Object;)V - Exception in thread “main” java.lang.NoSuchMethodError: org.jboss.resteasy.util.CaseInsensitiveMap.add(Ljava/lang/String;Ljava/lang/Object;)V 线程“主”中的异常java.lang.NoSuchMethodError:org.hibernate.cfg.Environment.verifyProperties(Ljava / util / Map;)V - Exception in thread “main” java.lang.NoSuchMethodError: org.hibernate.cfg.Environment.verifyProperties(Ljava/util/Map;)V 线程“主”java.lang.NoClassDefFoundError 中的异常:org/junit/platform/commons/util/ClassNamePatternFilterUtils - Exception in thread “main” java.lang.NoClassDefFoundError: org/junit/platform/commons/util/ClassNamePatternFilterUtils java.lang.NoSuchMethodError:org.springframework.util.ReflectionUtils.clearCache() - java.lang.NoSuchMethodError: org.springframework.util.ReflectionUtils.clearCache() 你好! Junit 平台 v.5.8.1 出现错误 java.lang.NoSuchMethodError: org.junit.platform.commons.util.AnnotationUtils.findAnnotation - Hello! Got an error with Junit platform v.5.8.1 java.lang.NoSuchMethodError: org.junit.platform.commons.util.AnnotationUtils.findAnnotation java.lang.NoSuchMethodError: org.springframework.util.ReflectionUtils.accessibleConstructor - java.lang.NoSuchMethodError: org.springframework.util.ReflectionUtils.accessibleConstructor 线程“main”中的异常 java.lang.NoSuchMethodError: org.apache.hadoop.conf.Configuration.getPassword(Ljava/lang/String;)[C - Exception in thread "main" java.lang.NoSuchMethodError: org.apache.hadoop.conf.Configuration.getPassword(Ljava/lang/String;)[C 线程“主”中的异常java.lang.NoSuchMethodError:org.openqa.selenium.io.FileHandler.unzip(Ljava / io / InputStream;)Ljava / io / File; - Exception in thread “main” java.lang.NoSuchMethodError: org.openqa.selenium.io.FileHandler.unzip(Ljava/io/InputStream;)Ljava/io/File;
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM