【问题标题】:Testing Spring Boot rest controller, unable to locate package for is()测试 Spring Boot 休息控制器,无法找到 is() 的包
【发布时间】:2018-11-23 02:51:02
【问题描述】:

我正在为 Spring Boot 中的 REST 控制器编写测试。是使用 is(),但我的 IDE 没有提示这是什么包,所以我找不到它。

这是我的测试方法;

@Test
    public void printerIsReady() throws Exception {
        /* Set the contents of status.txt to anything other than 3 */
        String statusFilePath = printerPath + "/status.txt";
        PrinterFileHelper.writeToFile("5", statusFilePath);

        this.mockMvc.perform(get("/printer"))
                .andExpect(status().isOk())
                .andExpect(jsonPath("$.status", is("READY")));

    }

我在网上找到了很多使用 is() 方法的示例,但完全不清楚我需要添加什么包才能访问它。

【问题讨论】:

    标签: spring-boot


    【解决方案1】:

    我在这里找到了答案How to check String in response body with mockMvc

    你需要导入的包是;

    import static org.hamcrest.Matchers.*;
    

    我需要将包添加到我的 pom.xml 文件中

    <dependency>
        <groupId>org.testinfected.hamcrest-matchers</groupId>
        <artifactId>core-matchers</artifactId>
        <version>1.5</version>
    </dependency>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-27
      • 2018-07-31
      • 2019-02-01
      • 1970-01-01
      • 2021-05-19
      • 2018-07-31
      • 2018-10-17
      • 1970-01-01
      相关资源
      最近更新 更多