使用WatiN对ASP.NET页面进行单元测试[3] 单元测试工具
BaseTestPage类可以通过这些信息运行服务器,所有继承了它的测试类都可以使用这个功能了。
下面是BaseTestPage类的完整代码:
public class BaseTestPage
{
static Process server = null;
static BaseTestPage()
{
if (Process.GetProcessesByName("WebDev.WebServer").Length == 0)
{
string webServerExePath = (string)ConfigurationManager.AppSettings["WebServerExePath"];
server = new Process();
Process.Start(webServerExePath, GetWebServerArguments());
}
}
public static string GetWebServerArguments()
{
string args = String.Format("/port:{0} /path:\"{1}\"", GetPort(), GetWebApplicationPath());
if (String.IsNullOrEmpty(args)) throw new ArgumentNullException("Arguments is not defined");
return args;
}
public static string GetPort()
{
string port = ConfigurationManager.AppSettings["Port"] as String;
if (String.IsNullOrEmpty(port)) throw new ArgumentNullException("Port is null or empty");
return port;
}
public static string GetWebApplicationPath()
{
string webApplicationPath = ConfigurationManager.AppSettings["WebApplicationPath"] as String;
if (String.IsNullOrEmpty(webApplicationPath)) throw new ArgumentNullException("WebApplicationPath is null or empty");
return webApplicationPath;
}
文章来源于领测软件测试网 https://www.ltesting.net/