How to solve synchronization problems in automated user interface tests with C # and Visual Studio?

Question

What is the standard approach for solving synchronization problems in automated user interface tests?

Specific example

I use Visual Studio 2010 and Team Foundation Server 2010 to create automated user interface tests and want to check if my application really stopped:

[TestMethod]
public void MyTestMethod()
{
    Assert.IsTrue(!IsMyAppRunning(), "App shouldn't be running, but is.");

    StartMyApp();
    Assert.IsTrue(IsMyAppRunning(), "App should have been started and should be running now.");

    StopMyApp();
    //Pause(500);
    Assert.IsTrue(!IsMyAppRunning(), "App was stopped and shouldn't be running anymore.");
}

private bool IsMyAppRunning()
{
    foreach (Process runningProcesse in Process.GetProcesses())
    {
        if (runningProcesse.ProcessName.Equals("Myapp"))
        {
            return true;
        }
    }
    return false;
}

private void Pause(int pauseTimeInMilliseconds)
{
     System.Threading.Thread.Sleep(pauseTimeInMilliseconds);
}

StartMyApp () and StopMyApp () were recorded in MS Test Manager 2010 and are located in UIMap.uitest.

The last statement is not executed because this statement is being executed while my application is still in the process of shutting down. If I put a delay after StopApp (), the test case will pass.

. ? - , , .

+3
2

StopMyApp. Process , Process.WaitForExit() .

+3

, . . . , .

+1

Source: https://habr.com/ru/post/1746968/


All Articles