【发布时间】:2020-03-07 18:10:41
【问题描述】:
我正在尝试在 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);
}
}
这是我得到的错误: 线程“主”java.lang.NoSuchMethodError 中的异常:org.junit.platform.commons.util.ReflectionUtils.getDefaultClassLoader()Ljava/lang/ClassLoader; 在 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)
这是我的 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>
【问题讨论】:
-
这有帮助吗? *.com/questions/45040070/…
-
不,我试过那个