Visual Studio 2010 で既定の MVC 4.0 インターネット Web アプリを作成しました。自動生成されたホーム コントローラー メソッドの 1 つで、右クリックして単体テストを作成しました。別の/新しいプロジェクトを選択します。テスト コードは次のようになります。
/// <summary>
///A test for Index
///</summary>
// TODO: Ensure that the UrlToTest attribute specifies a URL to an ASP.NET page (for example,
// http://.../Default.aspx). This is necessary for the unit test to be executed on the web server,
// whether you are testing a page, web service, or a WCF service.
[TestMethod()]
[HostType("ASP.NET")]
[AspNetDevelopmentServerHost("E:\\Backup 20080915\\Projects\\Writing Projects\\Blogs\\31a\\QUnitMVC\\jQueryMvcWebApp\\jQueryMvcWebApp", "/")]
[UrlToTest("http://localhost:61524/")]
public void IndexTest()
{
HomeController target = new HomeController(); // TODO: Initialize to an appropriate value
ActionResult expected = null; // TODO: Initialize to an appropriate value
ActionResult actual;
actual = target.Index();
Assert.AreEqual(expected, actual);
Assert.Inconclusive("Verify the correctness of this test method.");
}
VS によって完全に記述されたテストを実行すると、次のエラーで失敗します。
Failed IndexTest jQueryMvcWebApp.Test.HomeControllerTest.IndexTest The Web request 'http://localhost:61524/' completed successfully without running the test. This can occur when configuring the Web application for testing fails (an ASP.NET server error occurs when processing the request), or when no ASP.NET page is executed (the URL may point to an HTML page, a Web service, or a directory listing). Running tests in ASP.NET requires the URL to resolve to an ASP.NET page and for the page to execute properly up to the Load event. The response from the request is stored in the file 'WebRequestResponse_IndexTest.html' with the test results; typically this file can be opened with a Web browser to view its contents.
次の 3 つの属性をコメント アウトすると、テストは期待どおりに実行されます。
[HostType("ASP.NET")]
[AspNetDevelopmentServerHost("E:\\Backup 20080915\\Projects\\Writing Projects\\Blogs\\31a\\QUnitMVC\\jQueryMvcWebApp\\jQueryMvcWebApp", "/")]
[UrlToTest("http://localhost:61524/")]
だから私の質問は、なぜそれらがデフォルト設定なのか、いつコメントを外したままにしておくべきなのかということです.