3

问题

解决自动化 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() 之后延迟,则测试用例通过。

以上只是解释我的问题的一个例子。解决这些时间问题的标准方法是什么?一个想法是等待断言,直到我收到我的应用程序已停止的事件通知。

4

2 回答 2

3

您可以向 StopMyApp 添加一些同步。如果您附加到应用程序的 Process 对象,则可以使用Process.WaitForExit()等待程序完成。

于 2010-06-01T15:59:57.350 回答
1

看起来您正在尝试测试异步接口。这在自动化测试中效果不佳。你应该把它分成两个测试。每个测试都应该处理接口的一侧,而另一侧则被模拟。

于 2010-05-26T03:14:04.393 回答