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

“线程中的异常”;“主要”;java.lang.NoSuchMethodError:org.junit.platform.commons.util.ReflectionUtils.getDefaultClassLoader()Ljava/lang/ClassLoader;,java,wiremock,Java,Wiremock,我试图在Intellij上使用wiremock运行测试,但出现了错误。有人能帮我解决这个问题吗 public class Tests { private WireMockServer wireMockServer; @Before public void setup() { wireMockServer = new WireMockServer(8080); wireMockServer.start(); set

我试图在Intellij上使用wiremock运行测试,但出现了错误。有人能帮我解决这个问题吗

    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);
    }
}
以下是我得到的错误: 线程“main”java.lang.NoSuchMethodError中出现异常:org.junit.platform.commons.util.ReflectionUtils.getDefaultClassLoader()Ljava/lang/ClassLoader; 位于org.junit.platform.launcher.core.ServiceLoaderTestEngineeRegistry.loadTestEngines(ServiceLoaderTestEngineeRegistry.java:31) 位于org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:42) 位于com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:43)

这是我的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>

4.0.0
com.people.apitest
人类蜂巢试验
1.0-快照
com.github.tomakehurst
有线模拟
2.24.1
org.junit.jupiter
朱尼特木星发动机
5.5.2
测验
放心吧
放心
4.1.1
测验
com.jayway.restassed
json模式验证器
2.8.0

似乎wiremock和junit5之间存在依赖冲突。 当我查看mvncentral上的wiremock依赖项时,它表示它在()下面使用xmlunit

在该依赖项之后,您可以看到xmlunit在()下面使用Junit4

通过阅读公共JUnitAPI,我可以很好地找到“getDefaultClassloader”方法的版本。我建议您尝试删除对junit5的依赖,并使用junit4进行测试,看看这是否解决了类加载问题

如果您使用的是依赖关系管理器(mvn、gradle),则可以使用命令行或IDE列出有效的依赖关系。如果您看到junit的冲突版本,请在该路径上进行调查


编辑:另外,欢迎来到臭名昭著的“依赖地狱”

这有帮助吗?不,我试过了