如何从集成测试代码启动我的ASP.NET应用程序?

时间:2022-02-27 20:46:42

I have written a basic suite of Selenium integration tests for an application we are building. They work great. The only issue is that the application needs to be pre-deployed and running before the tests can run.

我为我们正在构建的应用程序编写了一套基本的Selenium集成测试。他们工作得很好。唯一的问题是应用程序需要预先部署并运行才能运行测试。

How do I launch an ASP.NET MVC application from integration test code?

如何从集成测试代码启动ASP.NET MVC应用程序?

1 个解决方案

#1


1  

I figured out how to launch my app my running MS build and then basically passing it the path to the sign and starting a new IISExpress process to host it:

我想出了如何启动我的应用程序运行MS构建,然后基本上传递给标志的路径并启动一个新的IISExpress进程来托管它:

ProcessStartInfo processStartInfo = new ProcessStartInfo()
{
   ErrorDialog = false,
   CreateNoWindow = true,
   UseShellExecute = false,
   Arguments = string.Format("/path:\"{0}\" /port:{1}", this.pathToSite, this.portNumber)
};

string path = (!string.IsNullOrEmpty(processStartInfo.EnvironmentVariables["programfiles(x86)"]) ? processStartInfo.EnvironmentVariables["programfiles(x86)"] : processStartInfo.EnvironmentVariables["programfiles"]) + "\\IIS Express\\iisexpress.exe";

processStartInfo.FileName = path;

this.iisProcess = new Process
{
  StartInfo = processStartInfo
};

this.iisProcess.Start();

Hope this helps the next guy. Otherwise I will just leave this here for my own reference. I wrapped all this in a method called when starting TestFixtureSetup. Of course I run

希望这有助于下一个人。否则我会把它留在这里供我自己参考。我在启动TestFixtureSetup时调用的方法中包含了所有这些。我当然跑了

public void Shutdown()
{
 if(this.IisExpressProcess == null)
 {
   return;
 }

 this.IisExpressProcess.Stop();
}

on TestFixtureTearDown.

在TestFixtureTearDown上。

#1


1  

I figured out how to launch my app my running MS build and then basically passing it the path to the sign and starting a new IISExpress process to host it:

我想出了如何启动我的应用程序运行MS构建,然后基本上传递给标志的路径并启动一个新的IISExpress进程来托管它:

ProcessStartInfo processStartInfo = new ProcessStartInfo()
{
   ErrorDialog = false,
   CreateNoWindow = true,
   UseShellExecute = false,
   Arguments = string.Format("/path:\"{0}\" /port:{1}", this.pathToSite, this.portNumber)
};

string path = (!string.IsNullOrEmpty(processStartInfo.EnvironmentVariables["programfiles(x86)"]) ? processStartInfo.EnvironmentVariables["programfiles(x86)"] : processStartInfo.EnvironmentVariables["programfiles"]) + "\\IIS Express\\iisexpress.exe";

processStartInfo.FileName = path;

this.iisProcess = new Process
{
  StartInfo = processStartInfo
};

this.iisProcess.Start();

Hope this helps the next guy. Otherwise I will just leave this here for my own reference. I wrapped all this in a method called when starting TestFixtureSetup. Of course I run

希望这有助于下一个人。否则我会把它留在这里供我自己参考。我在启动TestFixtureSetup时调用的方法中包含了所有这些。我当然跑了

public void Shutdown()
{
 if(this.IisExpressProcess == null)
 {
   return;
 }

 this.IisExpressProcess.Stop();
}

on TestFixtureTearDown.

在TestFixtureTearDown上。