评估CodedUI Test的结果在控制台应用程序中运行

时间:2015-11-25 15:26:07

标签: c# visual-studio-2015 coded-ui-tests

我正在尝试让控制台应用程序运行编码的UI测试而不依赖于安装的VSTest或Visual Studio等。

使用教程here我能够这样做,在我的解决方案中添加了两个没有在帖子中提到的DLL(我使用VS2015,我想依赖关系已经改变):< / p>

  

Microsoft.VisualStudio.TestTools.UITest.Extension.MSAA   Microsoft.VisualStudio.TestTools.UITest.WindowsStoreUtility

添加了上面两个DLL,以避免运行时异常抱怨那些丢失的DLL。

按原样运行Coded UI测试(根据教程):

Playback.Initialize();
CodedUITestInConsoleApp.CodedUI.CodedUITest1 test = new CodedUI.CodedUITest1();
test.CodedUITestMethod1();
Playback.Cleanup();

看起来测试确实在运行,但结果没有像我期望的那样被记录(将它们写入&#34; TestResults&#34;文件夹以及屏幕截图,并且控制台应用程序实际上没有报告运行测试的成功或失败。有关如何报告&#34; TestResults&#34;根据visual studio或vstest运行的任何想法?

在没有安装Visual Studio的Windows安装上尝试运行应用程序时,我现在遇到了一些额外的警告。我得到以下异常:

exception

我希望它会像找到DLL并将其作为项目引用一样简单,但是当我尝试这样做时,我得到以下内容:

enter image description here

我不知道从哪里开始,或者为什么我无法将此DLL添加到我的项目中。我只是希望能够从非VS /测试机器运行这些测试。这不可能吗?

1 个答案:

答案 0 :(得分:0)

通过执行以下操作,我能够确定运行测试的成功或失败:

class Program
{

    private static bool isInErrorState = false;

    static void Main(string[] args)
    {

        Console.WriteLine("Starting smoke test\n\n");

        Playback.Initialize();
        Playback.PlaybackError += Playback_PlaybackError;

        try
        {
            CodedUITestInConsoleApp.CodedUI.CodedUITest1 test = new CodedUI.CodedUITest1();
            test.CodedUITestMethod1();
        }
        catch (Exception ex)
        {
            if (!isInErrorState)
                CodedUITestMessage(ex.Message, false);
        }
        finally
        {
            Playback.Cleanup();
        }

        if (!isInErrorState)
            CodedUITestMessage("Successful smoke test.", true);

    }

    private static void Playback_PlaybackError(object sender, PlaybackErrorEventArgs e)
    {
        Playback.PlaybackError -= Playback_PlaybackError;
        isInErrorState = true;
        CodedUITestMessage("FAILURE running test.", false);
        Playback.StopSession();
    }

    private static void CodedUITestMessage(string message, bool isSuccess)
    {
        if (isSuccess)
            Console.ForegroundColor = ConsoleColor.Green;
        else
            Console.ForegroundColor = ConsoleColor.Red;

        Console.WriteLine(message);
        Console.ResetColor();
    }
}

虽然这解决了我能够找到运行测试的成功/失败状态的直接问题,但我仍在等待有关如何完成录制的反馈&#34; TestResults&#34;好像它是通过MSTest / Visual Studio运行的。