问题
解决自动化 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() 之后延迟,则测试用例通过。
以上只是解释我的问题的一个例子。解决这些时间问题的标准方法是什么?一个想法是等待断言,直到我收到我的应用程序已停止的事件通知。