我是Junit測試用例的新手,有人可以請我用下面的。用戶密碼重置的Junit測試用例
我需要爲用戶密碼重置編寫一個junit測試用例。我不知道我該如何使用斷言這裏:
public @ResponseBody userInfo updatePassword(@RequestBody Map<String, String> userLookup, HttpServletRequest request) {
userInfo userInfo = new userInfo();
try {
Users user = Service.getUserDetailsByUsername(userLookup.get("username"));
user.setPassword(userLookup.get("newPassword"));
Service.updateUserPw(user);
logger.debug("Password updated successfully");
} catch (Exception ex) {
logger.debug("Error while updating user password!", ex);
}
return userInfo;
}
method:getUserDetailsByUsername returns a user with the username passed.
method:setPassword returns return void
method: updateUserPw returns void
你試圖斷言無效的返回方法,會要求你檢查這個鏈接http://stackoverflow.com/questions/16043819/junit-testing-void-methods – Cleonjoys
鑑於這是一個控制器,你試圖測試這通過彈簧mvc?意思是通過「http」?或者你想要一個單元測試,使HTTP離開它? – xenoterracide
我可以離開它。 – fiddle