【发布时间】:2011-08-23 14:18:02
【问题描述】:
我是单元测试的新手,正在尝试学习 TDD,但我不知道 如何测试这个。我已经花了两天时间(不用担心它不是 对于雇主,所以请不要聪明的答案)。
我写了一个想要测试的控制器,我需要给它赋值 “选择”。简化后如下所示:
public ActionResult Index()
{
string s = Request["Choice"];
return View(new MyList.GetList(s));
}
我如何在测试中为“选择”分配一个值,或者我可以吗?在申请中, “Choice”的值由页面视图中表单中的单选按钮分配。 这是我在伪代码中的测试:
[TestMethod()]
public void IndexTest()
{
CategoryController target = new CategoryController();
var result = target.Index() as ViewResult;
MyList actual = result.ViewData.Model as MyList;
// etc ...
Assert.AreEqual(expected.List, actual.List);
}
谢谢, 马里奥
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-2 asp.net-mvc-3