我创建了默认的webservice asmx hello world:
namespace WebServiceHello
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
}
然后我使用Visual Studio生成一个MS测试并设置预期值:
[TestMethod()]
[HostType("ASP.NET")]
[AspNetDevelopmentServerHost("C:\\temp\\WebServiceHello\\WebServiceHello", "/")]
[UrlToTest("http://localhost:7352/")]
public void HelloWorldTest()
{
Service1 target = new Service1(); // TODO: Initialize to an appropriate value
string expected = "Hello World"; // TODO: Initialize to an appropriate value
string actual;
actual = target.HelloWorld();
Assert.AreEqual(expected, actual);
// Assert.Inconclusive("Verify the correctness of this test method.");
}
但我收到此错误消息:
Web请求 'http:// localhost:7352 /'已完成 成功没有运行测试。 配置时可能会发生这种情况 用于测试的Web应用程序失败( 发生ASP.NET服务器时出错 处理请求),或者当没有 执行ASP.NET页面(URL可以 指向HTML页面,Web服务, 或目录列表)。运行测试 在ASP.NET中需要URL来解决 到ASP.NET页面和页面到 正确执行Load事件。 请求的响应是 存储在文件中 'WebRequestResponse_HelloWorldTest.html' 与测试结果;通常这个 可以使用Web浏览器打开文件 查看其内容。
并作为测试文件: WebRequestResponse_HelloWorldTest.html 其中包含
<html>
<head>
<title>Directory Listing -- /</title>
<style>
body {font-family:"Verdana";font-weight:normal;font-size: 8pt;color:black;}
p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
h1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
h2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
pre {font-family:"Lucida Console";font-size: 8pt}
.marker {font-weight: bold; color: black;text-decoration: none;}
.version {color: gray;}
.error {margin-bottom: 10px;}
.expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
</style>
</head>
<body bgcolor="white">
<h2> <i>Directory Listing -- /</i> </h2></span>
<hr width=100% size=1 color=silver>
<PRE>
Saturday, September 25, 2010 06:39 PM <dir> <A href="App_Data/">App_Data</A>
Saturday, September 25, 2010 06:40 PM <dir> <A href="bin/">bin</A>
Saturday, September 25, 2010 06:39 PM <dir> <A href="obj/">obj</A>
Saturday, September 25, 2010 06:39 PM <dir> <A href="Properties/">Properties</A>
Saturday, September 25, 2010 06:39 PM 97 <A href="Service1.asmx">Service1.asmx</A>
Saturday, September 25, 2010 06:39 PM 572 <A href="Service1.asmx.cs">Service1.asmx.cs</A>
Saturday, September 25, 2010 06:44 PM 3,551 <A href="Web.config">Web.config</A>
Saturday, September 25, 2010 06:39 PM 968 <A href="web.config.backup">web.config.backup</A>
Saturday, September 25, 2010 06:39 PM 1,285 <A href="Web.Debug.config">Web.Debug.config</A>
Saturday, September 25, 2010 06:39 PM 1,346 <A href="Web.Release.config">Web.Release.config</A>
Saturday, September 25, 2010 06:40 PM 3,805 <A href="WebServiceHello.csproj">WebServiceHello.csproj</A>
Saturday, September 25, 2010 06:40 PM 1,086 <A href="WebServiceHello.csproj.user">WebServiceHello.csproj.user</A>
</PRE>
<hr width=100% size=1 color=silver>
<b>Version Information:</b> ASP.NET Development Server 10.0.0.0
</font>
</body>
</html>
测试不应该失败,因为实际是预期的,所以我做错了设置了吗?
答案 0 :(得分:4)
在带有服务的项目中创建Default.aspx页面
答案 1 :(得分:0)
答案适用于:Vista,VS2008(可能适用于VS2010)
http://msdn.microsoft.com/en-us/library/ms243399(v=vs.90).aspx