ASP.NET单元测试Windows7/IIS7

bgs*_*264 5 asp.net iis-7 unit-testing windows-7

今天花了几个小时尝试针对ASP.NET项目编写一些单元测试.这是Visual Studio 2010.

将Windows 7 Enterprise与IIS7配合使用.

我采取的步骤是:

  1. 为解决方案添加了新的测试项目
  2. 打开一个类文件作为网站的一部分(Member.vb)
  3. 在类文件中右键单击并"生成单元测试"
  4. 选择我想要生成存根的方法,选择添加到我的测试项目,单击OK
  5. 在测试项目中打开生成的MemberTest.vb文件,在其中一个生成的测试中单击,单击"在curent context中运行测试"

使用IIS6计算机的Windows XP Professional上执行这些精确步骤时,它可以正常工作.

但是在IIS7上的Windows 7 Enterprise机器上,我得到:

指定的URL('http:// localhost/MyProject')与有效目录不对应.配置为在IIS中的ASP.NET中运行的测试需要存在URL的有效目录.URL可能无效或可能未指向有效的Web应用程序.

所以发生了什么,我可以确认我可以浏览到http:// localhost/MyProject并且它显示完美.

我确信我在Windows/IIS中缺少某种配置,但我真的很茫然.

生成的测试方法:

<TestMethod(), _
 HostType("ASP.NET"), _
 UrlToTest("http://localhost/MyProject")> _
Public Sub MyMethodTest()
    Dim target As Member_Accessor = New Member_Accessor() ' TODO: Initialize to an appropriate value
    Dim CurrentVal As Short = 0 ' TODO: Initialize to an appropriate value
    Dim expected As Short = 0 ' TODO: Initialize to an appropriate value
    Dim actual As Short
    actual = target.MyMethod(CurrentVal)
    Assert.AreEqual(expected, actual)
    Assert.Inconclusive("Verify the correctness of this test method.")
End Sub
Run Code Online (Sandbox Code Playgroud)

(在ASP.NET论坛上交叉发布)

Lil*_*ver 1

您可能需要在项目属性中启用“使用 IIS”,然后单击“创建虚拟目录”。您安装了 IIS Express 吗?