我正在學習單元測試。如何使用NUnit和Rhino Mock對此方法進行單元測試?那麼我已經測試try
區塊,並且想要測試catch
區塊的代碼覆蓋範圍。如何對此方法的catch塊進行單元測試?
[HttpPost]
public ActionResult AppraisalOrderIsAcceptedByEmployee(int appraisalOrderId)
{
try
{
this.appraisalOrderService.SubmitAppraisalOrder(appraisalOrderId);
}
catch (MessageLoneException ex)
{
// Display validation errors
PersistErrors(ex);
// Remains on the same view
return RedirectToAction("VerifyOrderDetails", new { id = appraisalOrderId });
}
return GetLoginRedirectCurrentUser();
}
嘿謝謝你。我有一個問題。當我在aather類中編寫測試時,我應該使用反射來訪問測試用例的私有方法嗎? –
不,你應該**不**使用任何反射。你應該**不**單元測試私人方法。這是實施細節。您應該測試調用這些私有方法的公共方法。 –