springboot使用是org.mockito,这里也使用这个

HttpServletRequest request  = mock(HttpServletRequest.class);
when(request.getHeader("userInfo")).thenReturn("{}");
when(request.getHeaderNames()).thenReturn(new Hashtable().elements());
ServletRequestAttributes attributes = new ServletRequestAttributes(request);
RequestContextHolder.setRequestAttributes(attributes);

 

 

相关路径: https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features