質問
自動化された UI テストでタイミングの問題を解決するための標準的なアプローチは何ですか?
具体例
Visual Studio 2010 と Team Foundation Server 2010 を使用して自動化された UI テストを作成しており、アプリケーションの実行が本当に停止したかどうかを確認したいと考えています。
[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() と StopMyApp() は MS Test Manager 2010 で記録され、UIMap.uitest に存在します。
アプリケーションのシャットダウン処理中にアサーションが実行されるため、最後のアサートが失敗します。StopApp() の後に遅延を置くと、テスト ケースはパスします。
上記は、私の問題を説明するための単なる例です。この種のタイミングの問題を解決するための標準的なアプローチは何ですか? アプリが停止されたというイベント通知を受け取るまで、アサーションを待つというのが 1 つのアイデアです。