1.使用Unit Test Wizard创建单元测试.不必说
2.Copy WebService项目下面的Web.config到单元测试项目下,改名App.config,如有需要修改修改相应配置
3.HostType 注释掉
4.UrlToTest 修改为指定的webservice url
如下:
[TestMethod()]
// [HostType("ASP.NET")] 注释掉
[AspNetDevelopmentServerHost("E:\\Project\\Elp2.5\\source\\web\\ElpWeb\\ELPApp\\Elp.AppServices", "/")]
[UrlToTest("http://localhost:3166/UserService.asmx")]//asmx地址
public void LoginTest()
{
UserService target = new UserService(); // TODO: Initialize to an appropriate value
string userName = "test"; // TODO: Initialize to an appropriate value
string password = "edit"; // TODO: Initialize to an appropriate value
bool actul= target.Login(userName, password);
Assert.AreEqual(true, actul);
// Assert.Inconclusive("A method that does not return a value cannot be verified.");
}