在Azure DevOps测试运行任务中打印控制台输出 [英] Printing the Console output in the Azure DevOps Test Run task

查看:149
本文介绍了在Azure DevOps测试运行任务中打印控制台输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用[BeforeTestRun]挂钩进行一些初始的一次设置,以进行我的Specflow测试.这确实会检查某些用户以确保它们是否存在,如果不存在,则使用特定的角色和权限来创建它们,以便自动化测试可以使用它们.执行此功能的功能将在Console.Writeline上打印很多有用的信息. 当我在本地运行测试时,我可以在主要功能文件上看到此钩子函数的输出以及每个场景下每个场景的输出.但是,当我通过Azure DevOps pipleine运行测试时,我不确定[BeforeTestRun]的输出在哪里,因为它没有绑定到特定的测试方案. 运行测试任务"控制台没有有关此的信息.

I am doing some initial one off setup using [BeforeTestRun] hook for my specflow tests. This does check on some users to make sure if they exist and creates them with specific roles and permissions if they are not so the automated tests can use them. The function to do this prints a lot of useful information on the Console.Writeline. When I run the test in my local I can see the output from this hook function on the main feature file and the output of each scenario under each of them. But when I run the tests via Azure DevOps pipleine, I am not sure where to find the output for the [BeforeTestRun] because it is not bound a particular test scenario. The console of Run Tests Tasks has no information about this.

有人可以帮我在某处显示此输出,以便我采取相应的行动.

Can someone please help me to show this output somewhere so I can act accordingly.

我尝试使用System.Diagnostics.Debug.Print,System.Diagnostics.Debug.Print,System.Diagnostics.Debug.WriteLine,System.Diagnostics.Trace.WriteLine,但似乎在管道控制台上没有任何作用

I tried to use System.Diagnostics.Debug.Print, System.Diagnostics.Debug.Print,System.Diagnostics.Debug.WriteLine,System.Diagnostics.Trace.WriteLine but nothing seems to work on pipeline console

[BeforeTestRun]
        public static void BeforeRun()
        {
            Console.WriteLine(
                "Before Test run analyzing the users and their needed properties for performing automation run");
}

我希望我的输出在某处可见,这样我就可以根据需要采取行动.

I want my output to be visible somewhere so I can act based on that information if needed to.

推荐答案

控制台日志是不可能的.

It's not possible for the console logs.

该产品当前不支持通过打印控制台日志以通过测试,并且我们目前还没有计划在不久的将来对此进行支持.

The product currently does not support printing console logs for passing tests and we do not currently have plans to support this in the near future.

(来源:但是,还有另一种方法:

However, there's another way:

您的版本将带有文件扩展名.trx的附件.这是一个xml文件,其中包含每个测试的Output元素(另请参见 https://stackoverflow.com/a/55452011):

Your build will have an attachment with the file extension .trx. This is a xml file and contains an Output element for each test (see also https://stackoverflow.com/a/55452011):

<TestRun id="[omitted]" name="[omitted] 2020-01-10 17:59:35" runUser="[omitted]" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
  <Times creation="2020-01-10T17:59:35.8919298+01:00" queuing="2020-01-10T17:59:35.8919298+01:00" start="2020-01-10T17:59:26.5626373+01:00" finish="2020-01-10T17:59:35.9209479+01:00" />
  <Results>
    <UnitTestResult testName="TestMethod1">
      <Output>
        <StdOut>Test</StdOut>
      </Output>
    </UnitTestResult>
  </Results>
</TestRun>

这篇关于在Azure DevOps测试运行任务中打印控制台输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆