Reputation:
When using "Coded UI tests" in Visual Studio 2010, is there an easy way to start the application under test (AUT) only if the AUT is not already running?
I know that I can implement such a piece of startup code from scratch, but I wonder whether the Visual Studio test framework offers something out of the box.
Upvotes: 3
Views: 5501
Reputation:
It seems as if this can be done using this code:
[TestInitialize]
public void MyTestInitialize()
{
if (_application != null)
{
return;
}
Process[] processes = Process.GetProcessesByName("ApplicationUnderTest");
if (processes.Length > 0)
{
_application = ApplicationUnderTest.FromProcess(processes[0]);
}
else
{
_application = ApplicationUnderTest.Launch(@"C:\Path\To\ApplicationUnderTest.exe");
}
}
The AUT is launched only if it is not already running.
Upvotes: 7
Reputation: 679
There isn't a built in method to start an application if it isn't currently running that I am aware of.
It would be trivial to write something custom to do this just be sure that you are able to get your application under test into a known state so a previous test failure doesn't cause all tests run after it to fail. For web applications getting to a known state is likely as a simple as setting the URL but for complicated desktop applications it could be exceptionally complicated to get back to a known state.
Upvotes: 0