【发布时间】:2019-05-31 17:03:02
【问题描述】:
我的 Junit 测试出现如下嵌套异常:
Caused by: com.exception.Test1RestException: operation failed for test1
at com.testController.tests(Test1Controller.java:123)
.......................
Caused by: com.exception.Test2Exception: operation failed for test2
at com.testController.tests(Test2Controller.java:456)
..................
Caused by: com.exception.Test3RestException: operation failed for test3
at com.testController.tests(Test2Controller.java:789)
我想使用 mockmvc 验证“test3 操作失败”,在下面使用
代码
org.assertj.core.api.Assertions
.assertThatThrownBy(() ->
mockMvc.perform(fileUpload("/test/abc").file((MockMultipartFile) files))
.andExpect(status().isOk()))
.hasMessageContaining(operation failed for test3)
但我收到了预期的错误消息“操作失败 test1",任何指针都可以从我的 junit 到达底部消息
【问题讨论】:
标签: java spring-mvc junit mockito mockmvc