Mock代码
MockHttpServletRequest request = new MockHttpServletRequest(); request.setParameter("key", "value"); Class c = new Class(); request.getSession().setAttribute("key", c); RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));