问题
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.
回答1:
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);
回答2:
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>


来源:https://stackoverflow.com/questions/55594777/azure-devops-console-output-for-green-tests-is-missing