Search code examples
c#visual-studio-2010coded-ui-tests

Share Application under test object between multiple coded ui tests


I would like to start the application under test in a single test and use the opened application in the other tests. This is because starting the application takes quite sometime and it might be expensive if I repeat it for each test. I would like to have a single object of by AUT in the object map that is initialized along with the the UI map object.

This method fails because the object is not being passed between different tests even if it is static. Is there any solution to this issue?

UIMap

public partial class UIMap
{
    public ApplicationUnderTest _aut { get; set; }

    public void AUT_Open()
    {
        string AUTExecutable = ConfigurationManager.AppSettings["AUTExecutable"];
        _aut = ApplicationUnderTest.Launch(AUTExecutable );
    }
    ...
 }

Test

private static UIMap map;

[TestMethod]
public void Test01()
{
    ...
    this.UIMap.RecognitionDesigner_Open();
}

[TestMethod]
public void Test02()
{
    //Do something on the UIMap that tries to use the same member variable- _aut 
    //in the UIMap
}

Solution

  • I was able to solve this issue by using _aut.CloseOnPlaybackCleanup = false;. Apparently, the reference to the UIMap object seems to get lost at the end of each test method.

    public partial class UIMap
    {
        public ApplicationUnderTest _aut { get; set; }
    
        public void AUT_Open()
        {
             string AUTExecutable = ConfigurationManager.AppSettings["AUTExecutable"];
             _aut = ApplicationUnderTest.Launch(AUTExecutable );
             _aut.CloseOnPlaybackCleanup = false;
        }
        ...
    }