Coded UI Test: Why does application close after each test in Visual Studio 2012?

 In Visual Studio 2010 SP1, Coded UI Test added a flag CloseOnPlaybackCleanup to ApplicationUnderTest class. For cases where an application is launched during test run, this flag helps determine whether to close the application under test after test is over.  Default value for the flag was set to true (closes the application) as it is not advisable to re-use resources from other test cases. But although this flag was introduced, the Coded UI engine was not honoring the value due to a bug that we have fixed. As a result, all applications would continue to run even after the flag is set to true in VS 2010 SP1

Since the bug is fixed in Visual Studio 2012 users will see  BrowserWindow / ApplicationUnderTest is getting closed after each test case if they don’t have CloseOnPlaybackCleanup flag set to false. 

 If you want to reuse any application instance launched in another test case, you have to assign CloseOnPlaybackCleanup flag to false for ApplicationUnderTest / BrowserWindow object.

Please refer to sample code as below. If you run all these three tests together, BrowserWindow will be launched only once, remaining other tests will use existing browser instance from the previous test. If you run each test individually, then each test case will close the browser at the end of the run.



 The same principle is applied with running tests using Command Line. If you are running tests altogether, the Application Under test will remain open in between tests in case CloseOnPlaybackCleanup is set to false. Once the run is over, all application instances which were launched during the run are closed.