1

UPDATE:因此,只要我有像H ostType,AspNetDevelopmentServerHost,URLToTest這樣的所有元標記,就會發生錯誤。所以,當我評論這些標籤時,我可以運行測試,但我需要讓這些標籤具有控制器連接到數據庫的連接字符串。 我在asp.net mvc的行動創造了一個基本的單元測試僅通過右擊並說Create unit tests..。我是隻是想經營test.I正在此錯誤的基本單元 -在asp.net mvc中進行單元測試的問題?

The test adapter 'WebHostAdapter' threw an exception while running test 'IndexTest'. The web site could not be configured correctly; getting ASP.NET process information failed. Requesting 'http://localhost:55767/VSEnterpriseHelper.axd' returned an error: The remote server returned an error: (500) Internal Server Error.

這是我的方法 -

[TestMethod()] 
     [HostType("ASP.NET")] 
     [AspNetDevelopmentServerHost("C:\\Users\\Administrator\\Desktop\\MyWebsite\\Websites\\Customer1\\Customer1", "/")] 
     [UrlToTest("http://localhost:55767/Admin/Dashboard")] 
     public void IndexTest() 
     { 

      DashboardController target = new DashboardController(); // TODO: Initialize to an appropriate value 
      string id = string.Empty; // TODO: Initialize to an appropriate value 
      ActionResult expected = null; // TODO: Initialize to an appropriate value 
      ActionResult actual; 
      actual = target.Index(id); 
      Assert.AreEqual(expected, actual); 
      Assert.Inconclusive("Verify the correctness of this test method."); 
     } 

任何想法這裏的問題會是什麼?我試圖谷歌,但沒有得到一個很好的解決我的問題。我正在使用VS2010 Ultimate和asp.net mvc 2.0。

+0

如果可能,您可以發佈Index操作方法和控制器構造函數(如果有)? – HitLikeAHammer 2010-10-19 17:05:08

+0

我添加了示例代碼.. – Vishal 2010-10-20 14:45:20

回答

1

我在asp.net mvc的行動創造了一個基本的單元測試僅通過右擊並說創建單元測試..

當你這樣做的ASP.NET Web應用程序項目(這是MVC使用的)Visual Studio會產生大量的垃圾,並且會在每次運行單個單元測試時嘗試啓動Web服務器。你不想要這個。

這裏有兩種可能性:

  1. 當你開始一個新的ASP.NET MVC項目選擇要在默認模板中的單元測試項目(首選)。
  2. 您已經有了一個ASP.NET MVC項目,並且您想爲其添加單元測試。在這種情況下,只需右鍵單擊解決方案並添加一個類型爲Test Project的新項目。現在添加對您正在測試的ASP.NET MVC項目的引用,並添加一個新的單元測試(Add New Item)。
+0

我更新了我的問題..還有什麼其他的你認爲我需要知道的.. – Vishal 2010-10-20 14:45:09

+0

@Darin Dimitrov我認爲這個答案忽略了一個重要的問題:「...我需要讓這些標籤具有連接字符串可供控制器連接到數據庫...「爲了從web.config獲得連接字符串,您需要有一個正在運行的Web服務器。 – Dror 2012-12-04 18:35:56