【发布时间】:2013-10-10 23:54:13
【问题描述】:
[HttpGet]
[Authorize]
public ActionResult Create() //loads the form
{
var categoryList = new SelectList(new[] { "Electronics", "Toys","Books","Sporting Goods"}); //defines the categories
ViewBag.CategoryList = categoryList;
return View();
}
我为此写了一个测试方法..
[TestMethod]
public void TestCreate() {
AdvertisementController controller = new AdvertisementController();
var categoryList = new SelectList(new[] { "Electronics", "Toys", "Books", "Sporting Goods" });
ViewResult result = controller.Create() as ViewResult;
Assert.AreEqual(categoryList,result.ViewBag.categoryList);
}
但它失败了。我想知道这是什么情况。这有什么问题??
【问题讨论】:
-
失败说明了什么?
-
请准确描述问题所在(编译错误?异常?粘贴您看到的确切消息)。另外,将
new[]更改为new string[]。 -
我想你大约半小时前问过类似的问题......stackoverflow.com/questions/19173200/…
-
@ShahroozJefriㇱ。 Fail 表示单元测试失败!!!!
-
是的,测试失败了。这并不意味着代码不正确。我应该怎么做才能通过测试???
标签: c# unit-testing visual-studio-2012