@WebAppConfiguration
public class ControllerTest{
// 自己写的controller
@Autowired
private DemoController sendMsgController;
private MockMvc mockMvc;
@Before
public void setup() {
mockMvc = MockMvcBuilders.standaloneSetup(sendMsgController).build();
}
/**
* get带参数
* @throws Exception
*/
@Test
public void testSendMsg() throws Exception {
ReqSendMsgVO vo=new ReqSendMsgVO();
vo.setContent("您的验证码为8787,请在5分钟内使用");
TelVO telVO=new TelVO();
telVO.setMobile("123123123");
// vo.setTel(telVO);
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders
.post("/RecognitionMoneyConfirm/sendMsgNew.do",vo)
//.param("productId","x01")
)
.andExpect(MockMvcResultMatchers.status().isOk())
.andDo(MockMvcResultHandlers.print())
.andReturn();
logger.info(mvcResult.getResponse().getContentAsString());
}
}
mockmvc 用法
最新推荐文章于 2024-05-30 11:20:08 发布