springboot单元测试通过MockMvc类调用controller接口

@RunWith(SpringRunner.class)
@SpringBootTest
@WebAppConfiguration
@AutoConfigureMockMvc
public class ProjectRecipeControllerTest {

    @Autowired
    private MockMvc mockMvc;
 @Test
    public void save() throws Exception{

        ProjectRecipeVo vo = new ProjectRecipeVo();
        dto.setPatientNumber("1234564564");
        dto.setPatientId("YYHZ20190612LEEB");

        MvcResult mvcResult=mockMvc.perform(MockMvcRequestBuilders.post("/projectRecipe/save")
                .content(FastJsonUtil.toJSONString(vo)))
                .andReturn();
        int status=mvcResult.getResponse().getStatus();
        String content =mvcResult.getResponse().getContentAsString();

    }
}
posted @ 2021-03-04 17:13  我等的船还不来  阅读(113)  评论(0)    收藏  举报