Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing the Console output in the Azure DevOps Test Run task

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.

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.

like image 707
Nitin Verma Avatar asked Jun 26 '19 03:06

Nitin Verma


1 Answers

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.

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

However, there's another way:

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>

Build attachment

trx file with output

like image 194
riQQ Avatar answered Oct 13 '22 15:10

riQQ