【问题标题】:Making a custom Log During Coded Ui Test Run在编码的 UI 测试运行期间制作自定义日志
【发布时间】:2013-09-26 16:22:41
【问题描述】:

基本上我正在使用 MStest 运行一组编码的 ui 测试。

我正在尝试在测试运行时编写自定义日志文件。

例如,在每次测试结束时,如果测试通过,我想在文本文件中添加一行,显示“测试已通过”

最好输出到 TXT 文件。 通过扩展,我最终会将其输出到电子邮件中,但现在不需要。

在每个测试结束时我都在尝试这个基本级别

 if (this.testContextInstance.CurrentTestOutcome.Equals(true))
        {
            string lines = "Passed.";
            System.IO.StreamWriter file = new System.IO.StreamWriter("c:\test.txt");
            file.WriteLine(lines);
            file.Close();
        }
        else
        {
            string lines = "Failed.";
            System.IO.StreamWriter file = new System.IO.StreamWriter("c:\test.txt");
            file.WriteLine(lines);
            file.Close();
        }
    }

但我不完全理解 CurrentTestOutcome 方法。

目前我根本没有得到任何文件输出。

【问题讨论】:

    标签: c# visual-studio-2010 web-applications automated-tests coded-ui-tests


    【解决方案1】:

    CurrentTestOutcome 是一个枚举,参见 http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.testcontext.currenttestoutcome.aspxhttp://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.unittestoutcome.aspx 。所以我不确定问题的this.testContextInstance.CurrentTestOutcome.Equals(true) 达到了什么效果。

    类似以下的内容应该显示您想要的内容:

    string lines = "Failed.";
    System.IO.StreamWriter file = new System.IO.StreamWriter("c:\test.txt");
    file.WriteLine(this.testContextInstance.CurrentTestOutcome.ToString());
    file.Close();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-08
      • 1970-01-01
      • 1970-01-01
      • 2020-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多