使用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;
}
文章來源于領測軟件測試網 http://www.kjueaiud.com/