I am trying to write a unit test for one of the interceptors in my spring-mvc rest application. I am using:
- TestNG 6.8.7 - Mockito 1.9.5 - Spring 4.0.0
Is it mandatory to have controllers to unit test the interceptors? Can we write a unit test without writing controller?
Thanks,NN
Assuming you mean HandlerInterceptor,
Is it mandatory to have controllers to unit test the interceptors?
No. A unit test is meant to be as self contained as possible. If you're unit testing the HandlerInterceptor implementation, the only things involved are your implementation and all of its dependencies.
Can we write a unit test without writing controller?
Yes. HandlerInterceptor is just an interface with three (3) methods. None of those methods require a controller, so you don't need a controller.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With