【单元测试】Mock对象ServletRequestAttributes

Mock代码
    MockHttpServletRequest request = new MockHttpServletRequest();

    request.setParameter("key", "value");
        
    Class c = new Class();
    
    request.getSession().setAttribute("key", c);

    RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));

 

posted @ 2020-12-24 20:10    阅读(1686)  评论(0编辑  收藏  举报