The title explains my question 100%. Let assume there is @ControllerAdvice
annotated class in Spring Boot/MVC. In my case it contains @ExceptionHandler
annotations. Ok, I can do unit-test of this class (it returns formatted JSON with information from Exception class). It is easy - especially when using Spock.
But what about integration tests? The only way to test if my usage of Spring library is right is to create controller that only exists for testing purposes, add some methods to it that eg. throw exception of specific kind and see if it returns what I designed @ControllerAdvice
to return. But it seems ugly - creating additional code only for testing of existing code.
So my questions is - how do You do integration-tests on @ControllerAdvice
? Do You just do not do it, create special controller only to test @ControllerAdvice
or just test it using existing controller providing it for example with wrong data that will result in exception being thrown (in my case, if it was @InitBinder
methods we will check ModelAndView
)?