Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure DevOps: Console output for green tests is missing

We migrated our NUnit tests execution from TeamCity to Azure DevOps. One of the biggest issues so far - there is no way to see Console output for green (passed) tests. Is this basic feature really missing in DevOps, or I simply do not know where to look?

Here is how to view Console output for failed tests:

Console outpur for failed tests

UPDATE: In the documentation there is a "Tip" (https://docs.microsoft.com/en-us/azure/devops/pipelines/test/review-continuous-test-results-after-build?view=azure-devops):

If you use the Visual Studio Test task to run tests, diagnostic output logged from tests (using any of Console.WriteLine, Trace.WriteLine or TestContext.WriteLine methods), will appear as an attachment for a failed test.

Text explicitly states "for a failed test". Looks like there is indeed no way (no easy way) to see Console output for non-failed tests, which is very discoureging.

like image 839
Roman Avatar asked Apr 09 '19 14:04

Roman


People also ask

Can I export test results from Azure DevOps?

For Azure DevOps Server 2020 and later versions, you can copy test cases from within a project or another project to a test suite, or you can use the Grid view to copy and paste test cases from one suite to another. Optionally, you can bulk import and export test cases.

What is output variable in Azure DevOps?

An output variable is a specific kind of pipeline variable that is created by a task. The deployment task assigns a value to a variable which then makes it available to use across a pipeline.


Video Answer


2 Answers

Azure DevOps does not show Console output for passed tests:

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.


They recommend writing the Console output to a file and uploading the file as a test attachment:

However, to achieve what you want, you are almost in the right path. Writing the necessary info to a file and uploading as test attachment is the right approach. You can use this API to attach the file and it will be automatically uploaded as test case level attachment in azure devops : https://docs.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.testtools.unittesting.testcontext.addresultfile?view=mstest-net-1.2.0


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


There's another way to get the output for successful test:

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 96
riQQ Avatar answered Sep 25 '22 19:09

riQQ


So yes, it does look like this is a missing feature in DevOps.

The (only?) workaround we could come up with was to write all our Console outputs to a log file... And then adding this log file as an attachment in test's TearDown method:

TestContext.AddTestAttachment(testLogs);

like image 38
harveyAJ Avatar answered Sep 25 '22 19:09

harveyAJ