I like the new way of writing web tests with @SpringBootTest and TestRestTemplate :+1: :heart:

However, we have tests that are expecting error codes (e.g. UNAUTHORIZED, FORBIDDEN) to be returned. The TestRestTemplate ignores them and thats where the lovestory comes to an end.

Since the TestRestTemplate bean is automatically available whenever @SpringBootTest is used it would be nice to have a configuration property on this annotation to configure the fault tolerancy.

What about @SpringBootTest(webIgnoreClientErrors=true|false)? Any thoughts on this?

Comment From: wilkinsona

@markbigler The error codes aren't exactly ignored, but HttpClientErrorException and HttpServerErrorException aren't thrown. You can still access them via ResponseEntity.getStatusCode(). IMO, this behaviour is preferable as it makes it easier to assert that the error response has the desired status code, headers, body etc without using a try-catch block.

If you'd like to restore the exception-throwing behaviour you can call testRestTemplate.setErrorHandler(new DefaultResponseErrorHandler()).

Comment From: spyro2000

I would personally prefer Spring not throwing away my explicitly configured error handler in the rest template builder...

Comment From: wilkinsona

@spyro2000 That's been discussed previously. Please see https://github.com/spring-projects/spring-boot/issues/7265 for details.