两种方式

  1. 测试 该接口的单元测试的方法,在@Test 里面加上异常的 class名称
@Test(expectedExceptions= {NestedServletException.class})
public void testCreateServiceWithInvalidParamters() throws Exception {
  .....
}
  1. 使用 try catch 接收
@Test
public void testCreateServiceWithInvalidParamters() throws Exception {
  .....
   try {
            mvc.perform(request).andReturn();
        } catch (NestedServletException e) {
            assertTrue(e.getCause().getMessage().endsWith(ROLLBACK_SERVICE_REQUEST_PARAM_EMPTY));
        }
}

相关文章:

  • 2022-02-14
  • 2021-12-06
  • 2022-12-23
  • 2021-04-21
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-26
  • 2021-10-09
  • 2021-07-07
  • 2021-07-04
  • 2021-05-02
相关资源
相似解决方案