在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)
我想使用嘲笑来验证“ 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到达底部消息
答案 0 :(得分:0)
通过使用.hasStackTraceContaining(message)方法调用来工作