.netunit-testingazure-devops

Azure devops test task: how to display messages during Visual Studio test execution


I have some unit tests which can take several time to complete the execution. In these I added some messages to show the unit test progress, using Console.WriteLine.

In my pipeline, during the "Visual Studio Test" task these messages aren't shown. I'd like to see them during the test execution, through the details log view.

enter image description here

Is there any way to achieve this result?


Solution

  • I'm afraid it's not possible for the console logs. 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.

    enter image description here

    However, a full test run output is available in the trx file found in the test run. If you open the trx file from the Notepad, you will see there is an Output element for each test:

    enter image description here

     <UnitTestResult executionId="xxx" testId="xxx" testName="M2Test" computerName="xxxx" duration="00:00:00.0001844" startTime="2021-01-14T08:10:11.5942741+00:00" endTime="2021-01-14T08:10:11.5962978+00:00" testType="13cdc9d9-xxxx" outcome="Passed" testListId="8cxxxx" relativeResultsDirectory="504xxxxx">
          <Output>
            <StdOut>cecehi</StdOut>
          </Output>
        </UnitTestResult>