Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用C#和Visual Studio解决自动化UI测试中的计时问题?_C#_Visual Studio_Automated Tests_Coded Ui Tests - Fatal编程技术网

如何使用C#和Visual Studio解决自动化UI测试中的计时问题?

如何使用C#和Visual Studio解决自动化UI测试中的计时问题?,c#,visual-studio,automated-tests,coded-ui-tests,C#,Visual Studio,Automated Tests,Coded Ui Tests,问题 在自动化UI测试中,解决计时问题的标准方法是什么 具体例子 我使用VisualStudio 2010和Team Foundation Server 2010创建自动化UI测试,并想检查我的应用程序是否真的停止运行: [TestMethod] public void MyTestMethod() { Assert.IsTrue(!IsMyAppRunning(), "App shouldn't be running, but is."); StartMyApp();

问题

在自动化UI测试中,解决计时问题的标准方法是什么

具体例子

我使用VisualStudio 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()之后加上延迟,测试用例就会通过


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

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

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

你能详细说明一下吗?对于MyTestMethod示例,这会是什么样子?谢谢。因为函数StopMyApp在它完成它应该做的事情之前返回,所以你不能测试它。您只能在StopMyApp内部测试代码。我不能告诉你怎么做,因为我不知道里面是什么,里面是一段由编码的UI测试生成器生成的代码。它只是打开“文件”菜单并单击“退出”菜单项。public void StopMyApp(){#区域变量声明WpfMenuItem uIExitMenuItem=this.UIActusWindow1.UIRadMenuMenu.UIFileMenuItem.uIExitMenuItem;#endregion//单击“文件”->“退出”菜单项鼠标。单击(uIExitMenuItem,新点(92,11));}+1这是一个非常酷的解决方案。我不知道。作品谢谢