在编码的Ui测试运行期间进行自定义日志

时间:2013-09-26 16:22:42

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

基本上我正在使用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方法。

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

1 个答案:

答案 0 :(得分: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();