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:
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.
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.
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.
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>
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With