我正在尝试为我的 spring-mvc rest 应用程序中的其中一个拦截器编写单元测试。我正在使用:
- TestNG 6.8.7 - Mockito 1.9.5 - Spring 4.0.0
是否必须让 Controller 对拦截器进行单元测试?我们可以在不编写 Controller 的情况下编写单元测试吗?
谢谢,NN
最佳答案
假设你的意思是HandlerInterceptor
,
Is it mandatory to have controllers to unit test the interceptors?
没有。单元测试意味着尽可能独立。如果您正在对 HandlerInterceptor
实现进行单元测试,那么唯一涉及的就是您的实现及其所有依赖项。
Can we write a unit test without writing controller?
是的。 HandlerInterceptor
只是具有三 (3) 个方法的接口(interface)。这些方法都需要 Controller ,因此您不需要 Controller 。
关于java - 如何在没有 Controller 类的情况下对 spring mvc 拦截器进行单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22626100/