0
我確實爲以下方法生成了測試用例;它返回Action結果 - 一個json「Success」字符串。如何修改生成的腳本?寫單位返回行動結果的方法的測試用例
public ActionResult LoginClick(string username, string password)
{
LoginRepo loginrepo = new LoginRepo();
BL bl = new BL();
bool loginStatus = loginrepo.CheckLogin(username, password);
if (loginStatus)
{
bl.SetSessionVariable("Username", username);
return Json(new { Status = "Success" }, JsonRequestBehavior.AllowGet);
}
return Json(new { Status = "Failed" }, JsonRequestBehavior.AllowGet);
}
以下是生成的測試用例。
[TestMethod()]
[HostType("ASP.NET")]
[UrlToTest("http://localhost:1280")]
public void LoginClickTest()
{
LoginController target = new LoginController(); // TODO: Initialize to an appropriate value
string username = null; // TODO: Initialize to an appropriate value
string password = null; // TODO: Initialize to an appropriate value
ActionResult expected = null ; // TODO: Initialize to an appropriate value
ActionResult actual;
actual = target.LoginClick(username, password);
Assert.AreEqual(expected, actual);
Assert.Inconclusive("Verify the correctness of this test method.");
}
我該如何修改它以便它可以成功運行?既然它的行爲結果和數據是json字符串應該預期什麼,實際結果?我應該如何寫assert?
他回答有幫助嗎? – SBirthare 2014-10-31 06:13:59