如何使用 mockmvc 从嵌套异常中获取底部错误消息

how to get bottom error message from a nested exception using mockmvc

我的 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验证"operation failed for 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 到达底部消息的指针

它通过使用 .hasStackTraceContaining(message) 方法调用来工作