![](/img/trans.png)
[英]How to unit test exception message thrown inside try and caught by catch using 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来验证“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(消息),方法调用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.