我有一个控制器方法,我必须为此编写一个 junit 测试
@RequestMapping(value = "/new", method = RequestMethod.GET)
public ModelAndView getNewView(Model model) {
EmployeeForm form = new EmployeeForm()
Client client = (Client) model.asMap().get("currentClient");
form.setClientId(client.getId());
model.addAttribute("employeeForm", form);
return new ModelAndView(CREATE_VIEW, model.asMap());
}
使用 spring mockMVC 进行 Junit 测试
@Test
public void getNewView() throws Exception {
this.mockMvc.perform(get("/new")).andExpect(status().isOk()).andExpect(model().attributeExists("employeeForm")
.andExpect(view().name("/new"));
}
我得到 NullPointerException 作为 model.asMap().get("currentClient"); 运行测试时返回 null,如何使用 spring mockmvc 框架设置该值