java - Hamcrest Matcher 签名者信息与同一包中其他类的签名者信息不匹配

标签 java spring-boot junit integration-testing hamcrest

我正在尝试使用 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:
enter image description here

enter image description here

如何设置 Eclipse 环境以使用 REST-Assured 和 Hamcrest?为什么会抛出这个异常?

最佳答案

我从我的 .p2 插件文件夹中删除了 org.hamcrest.core_1.3.0.v201303031735.jar,它对我有用。

  • 我在“C:\Users\Dell.p2\pool\plugins”文件夹中搜索了“hamcrest”,并在那里找到了“org.hamcrest.core_1.3.0.v201303031735.jar”。
  • 我为此路径删除了它。
  • 尝试运行测试用例,它在 statusCode() 中没有失败地通过了。方法行。

  • 请建议是否有人有更好的解决方案。

    关于java - Hamcrest Matcher 签名者信息与同一包中其他类的签名者信息不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59963733/

    相关文章:

    java - 为什么我的 Bean 在 Junit 测试中不符合 Autowire Candidate 资格?

    gradle - 如何从gradle创建junit5 Maven POM文件?

    java - 如何在 Swing 中使用拖放来获取文件路径?

    java - Spring/Hibernate 应用程序中的角色/权限

    java - java双向链表插入排序算法

    Java Spring Boot 应用程序 : Error creating bean with name, 预计至少有 1 个有资格作为此依赖项的 Autowiring 候选者的 bean

    java.lang.OutOfMemoryError : PermGen space in play framework

    java - 在 Spring Boot Gradle 项目中导入 JWT(JSON Web Token)有困难

    java - 是否可以使用 jpa 的 sql Developer 检索自动递增的字段

    java - 如何使 junit 测试在 springboot 应用程序中使用嵌入式 mongoDB?