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

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

问题描述

我正在使用 [BeforeTestRun] 钩子为我的规范流测试做一些初始一次性设置.这确实会检查某些用户以确保它们是否存在,如果不存在,则使用特定的角色和权限创建它们,以便自动化测试可以使用它们.执行此操作的函数会在 Console.Writeline 上打印许多有用的信息.当我在本地系统上运行测试时,我可以在主功能文件上看到这个钩子函数的输出,以及每个场景下每个场景的输出.但是当我通过 Azure DevOps pipleine 运行测试时,我不确定在哪里可以找到 [BeforeTestRun] 的输出,因为它没有绑定特定的测试场景.Run Tests Tasks 的控制台没有这方面的信息.

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 on my local system 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.PrintSystem.Diagnostics.Debug.PrintSystem.Diagnostics.Debug.WriteLine> 和 System.Diagnostics.Trace.WriteLine,但似乎在管道控制台上没有任何效果.

I tried to use System.Diagnostics.Debug.Print, System.Diagnostics.Debug.Print, System.Diagnostics.Debug.WriteLine and 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.

推荐答案

控制台日志不可能.

该产品目前不支持打印控制台日志以通过测试,我们目前没有计划在不久的将来支持此功能.

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.

(来源:https://developercommunity.visualstudio.com/content/problem/631082/printing-the-console-output-in-the-azure-devops-te.html)

然而,还有另一种方式:

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天全站免登陆