单元测试

只要将第一条链注入到test类,通过mock就可以了。
@Resource(name = "springSecurityFilterChain", type = Filter.class)
Filter springSecurityFilterChain;

MOCK的时候要注意
MockServletContext servletContext = new MockServletContext();
servletContext.setContextPath("/security");
这里的servletContext是必须的,servletContext.setContextPath("/security");也是必须的
MockHttpServletRequest request = new MockHttpServletRequest(
servletContext, "post", "/login");
还需要加入一步,
request.setServletPath("/login");
这里的servletpath也是必须的。
MockFilterChain filterChain = new MockFilterChain();
springSecurityFilterChain.doFilter(request, response, filterChain);

你可能感兴趣的:(单元测试)