0
的模擬我有這個位指示方法:如何使用MockMvc與控制器
@RequestMapping(value = "/addEvent", method = RequestMethod.POST)
public String addEvent(Model model,
@Valid @ModelAttribute("myEvent") Event event,
BindingResult result, RedirectAttributes redirectAttributes,
@RequestParam(required = true) Integer selectedEventTypeId,
@RequestParam(required = true) Integer selectedEventStatusId) {
if (result.getErrorCount() > 1){
return "eventDetailsAdd";
}
eventService.addEvent(event, selectedEventTypeId, selectedEventStatusId);
redirectAttributes.addAttribute("idEvent", event.getId());
redirectAttributes.addAttribute("message", "added correctly at " + new Date());
return "redirect:eventDetails";
}
使用mockMvc我想嘲弄結果,並在if (result.getErrorCount() > 1)
兩個varians檢查我如何能做到嗎?
如果我使用MockMvc,什麼result.andExpect(MockMvcResultMatchers.view()名(/ *我可以期待在這裏?* /)) – gstackoverflow
@gstackoverflow你可以這樣做的,但你不會不要嘲笑'BindingResult'。你將不得不發送使'Event'參數無效的請求參數。 –
如何通過http請求使事件失效? – gstackoverflow