如果我这样写测试并且它不会在测试中被 WebExceptionHandler 捕获
@RunWith(SpringRunner.class)
@SpringBootTest
@EnableAutoConfiguration
public class projectTest {
@Test
public void test ()
{
if(true)
{
throw new NullPointerException();
}
}
}
在 WebExceptionHandler
@ControllerAdvice
@Slf4j
public class WebExceptionHandler {
@ExceptionHandler(NullPointerException.class)
@ResponseBody
public void customerException(NullPointerException e) {
System.out.println("handle the excpetion");
}
}
如何测试 WebExceptionHandler ?