我正在尝试使用 REST-Assured 和 JUnit5 在我的 Spring Boot 应用程序中编写一些集成测试,但是当我运行以下命令时:
@SpringBootTest(classes = ProductsApplication.class)
class ProductsApiTest {
@Before
public void setup() {
RestAssured.baseURI = "http://localhost:8080/test/api/products";
}
@Test
public void test1() {
ValidatableResponse statusCode = given().when().get().then().statusCode(200);
}
}
出现一个令人讨厌的错误:
java.lang.SecurityException: class "org.hamcrest.Matchers"'s signer information does not match signer information of other classes in the same package
请看一下我的 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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
...
<dependencies>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<scope>test</scope>
</dependency>
...
<!-- https://mvnrepository.com/artifact/io.rest-assured/rest-assured -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
</dependency>
</dependencies>
<build>
...
</build>
</project>
以下是 Eclipse 项目使用的 Order 和 Export + Libraries:
如何设置 Eclipse 环境以使用 REST-Assured 和 Hamcrest?为什么会抛出这个异常?
最佳答案
我从我的 .p2 插件文件夹中删除了 org.hamcrest.core_1.3.0.v201303031735.jar,它对我有用。
statusCode()
中没有失败地通过了。方法行。 请建议是否有人有更好的解决方案。
关于java - Hamcrest Matcher 签名者信息与同一包中其他类的签名者信息不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59963733/