3

I have a controller advice:

@ControllerAdvice
public class MyExceptionHandler {
  @ExceptionHandler(Exception.class)
  public void handleException(Exception ex) {
    ...
  }
}

And when testing the exception handler is not working:

@RunWith(SpringRunner.class)
@SpringBootTest(classes = {TestConfiguration.class})
public class MyTest {
  @Autowired
  private WebApplicationContext context;

  @Before
  public void setUp() throws Exception {
    RestAssuredMockMvc.webAppContextSetup(context);
  }

  @Test
  public myTestMethod() throws Exception {
     when().get("/controller").then().status(INTERNAL_SERVER_ERROR.value());
  }

  @After
  public void tearDown() throws Exception {
    RestAssuredMockMvc.reset();
  }
}

It just throws the exception, and the controller advice never captured it.

How can I make rest-assured work with ControllerAdvice in a whole context setup situation.

4

0 回答 0