阅读背景:

spring boot项目测试controller和service的方法

来源:互联网 

测试controller

@RunWith(SpringRunner.class)
@SpringBootTest(classes = {MainApplication.class,MockServletContext.class})
public class ReindexTest {

    private static final Logger LOGGER = LoggerFactory.getLogger(ReindexTest.class);


    private MockMvc mockMvc;

    @Autowired
    private WebApplicationContext webApplicationContext;

    @Before
    public void setUp() {
        mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
    }

    @Test
    public void testDeleteAllHistory() {
        try {
            MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post("/es/deleteHistory").param("userId",
                    "419"))
                    .andReturn();
            LOGGER.info(mvcResult.getResponse().getContentAsString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
@RunWith(SpringRunner.class)



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: