2011-04-20 50 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

相關問題