此功能用于更新数据库中的用户详细信息。有人可以帮我编写此功能的测试用例。
@RequestMapping(value = "/updateDetails", method = RequestMethod.POST)
public String updateVendorDetails(@Valid @ModelAttribute("users") Users users, BindingResult result,Model model) {
logger.info("{}.{}",new VendorController().getClass().getPackageName(), new VendorController().getClass().getName());
if(result.hasErrors()) {
model.addAttribute("edit","edit");
logger.warn("Function: updateVendorDetails(), Information: Error while updating vendor details");
return register.toString();
}
userDao.updateVendorDetails(users);
logger.info("Function: updateVendorDetails(), Information: Vendor details updated successfully");
return vendor.toString();
}
更新
代码:
mockMvc.perform(post(“ / updateDetails”)。accept(MediaType.TEXT_HTML).params(params))。andExpect(status()。isOk());
产生的错误:
这表示禁止发布方法,我的测试失败
关于您的更新:
感谢您澄清帖子中的特定错误/特定问题。
针对该特定错误-HTTP 403: Forbidden
-这应该可以解决问题:
Unit test Springboot MockMvc returns 403 Forbidden。
'希望有帮助!