我使用的是Spring boot 1.5.6版本和JUnit 4.11。在一个特定的Spring控制器中,我有一个方法,它以这种方式结束……
@RequestMapping(value= "/chipset/add", method = RequestMethod.POST)
public String addChipSet(@ModelAttribute("chipset") Chipset c){
this.chipsetService.addChipset(c);
return "redirect:/chipset";
}在我的JUnit测试中,我如何验证从提交到控制器的返回,其中返回了此重定向?我以前用过
@Test
public void addChipsetTest() throws Exception {
mockMvc.perform(post("/chipset/add"))
.andExpect(status().isOk())
.andExpect(redirectedUrl("chipset/redirect"));
}但这是在抛出java.lang.NullPointerException
所以请一定要帮帮我
发布于 2017-09-20 22:44:47
你没有在post测试请求中传递芯片组c参数,我认为是this.chipsetService.addChipset(c);抛出了nullPointerException。
https://stackoverflow.com/questions/46324913
复制相似问题