spring-boot - 测试 Spring Boot 休息控制器,无法找到 is() 的包
问题描述
我正在为 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() 方法的示例,但是完全不清楚我需要添加什么包才能访问它。
解决方案
我在这里找到了答案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>
推荐阅读
- scala - 级联可以重写/替换 Apache Spark 和 Scala 吗?是不是更优化?
- javascript - VueJS - 过滤对象数组并将 $route.params 与属性值进行比较
- r - 为什么抑制 Rmarkdown 中的错误不起作用?
- python - 在我的数据框中添加一个计数器列,该列根据温度值增加(在其他列中)
- postgresql - 带有 Knex 的 Postgres - 查询数组包含特定值的位置
- typescript - 装饰函数 Typescript 定义
- java - 如何从文件中解析 JSON?
- vb.net - 有没有办法简化这段代码?这里是 Visual Basic
- macos - lldb 不允许设置断点也不允许列出源文件
- python - python没有在max()中显示值