2011-04-20 79 views
0

我正在开发asp.net mvc3上的单元测试。当我运行一个defaultly创建测试的测试方法:Assert.AreEqual失败。预计:<(null)>。 Actual:<System.Web.Mvc.ViewResult>

[TestMethod()] 
     public void IndexTest() 
     { 
      ConferenceController target = new ConferenceController(); // TODO: Initialize to an appropriate value 
      ActionResult expected = Index; // TODO: Initialize to an appropriate value 
      ActionResult actual; 
      actual = target.Index(); 
      Assert.AreEqual(expected, actual); 
      Assert.Inconclusive("Verify the correctness of this test method."); 
     } 

此错误发生[TestMethod()]

Assert.AreEqual失败。预计:<(null)>。实际:。

如何传递断言?

回答

2
ActionResult expected = Index; // TODO: Initialize to an appropriate value 

由于注释表示您应该将Index变量初始化为适当的值。例如:

[TestMethod] 
public void Index() 
{ 
    // Arrange 
    HomeController controller = new HomeController(); 

    // Act 
    ViewResult result = controller.Index() as ViewResult; 

    // Assert 
    Assert.AreEqual("Welcome to ASP.NET MVC!", result.ViewBag.Message); 
} 
+0

刚读单元测试方法的本发明内容,解给出上面没有工作///

///一种用于索引测试/// // TODO:确保UrlToTest属性指定指向ASP.NET页面的URL(例如// http://.../Default.aspx)。这对于在Web服务器上执行单元测试是必需的,//是否测试页面,Web服务或WCF服务。现在执行上面的错误后会出现....... ???????????? – Divya 2011-04-20 12:49:57

相关问题