Azure DevOps – PublishTestResults@2 not displaying spaces at new lines in JUnit XML Output Correctly

I’m currently facing an issue with Azure DevOps’ PublishTestResults@2 task, specifically related to the display of spaces at the beginning of new lines in JUnit XML output. While the test results are published successfully, the formatting in the Azure DevOps test tab seems to ignore leading spaces in the output, affecting readability.

Objective:

My primary goal is to accurately display XML formatted snippets in either the error message or stack trace when a test fails.

  1. Using XML Tags:

    <failure>
      &lt;Failure&gt;
        &lt;something&gt;&lt;/something&gt;
      &lt;/Failure&gt;
    </failure>
    
    • Result: New lines are respected, but not the spaces. Also, closed tags are incorrectly interpreted as hyperlinks. Image with the result
  2. Using CDATA Section:

    <failure>
      <![CDATA[
        <Failure>
          <Something>
      ]]>
    </failure>
    
    • Result: Similar to the first approach; new lines are respected, spaces are ignored, and closed tags are misinterpreted.
  3. Using ‘message’ Attribute:

    <testcase classname="d" name="d5">
      <failure message="&lt;Failure&gt;\n  &lt;Something'&gt;\n  &lt;/Something&gt;\n&lt;/Failure&gt;"></failure>
    </testcase>
    
    • Result: The message is displayed as a single line, ignoring the newline characters \n.

Additional Context:

  • When viewing the test failure report directly, the formatting appears correct. The issue is specifically with how it’s displayed in the pipeline results (test tab) on Azure DevOps. Stack trace example in the report(expected result)

  • The XML is being generated and parsed correctly; the issue seems to be with how it’s presented in the “Tests” tab for the failed tests.

Seeking Suggestions:

I am looking for any advice or suggestions on how to resolve this formatting issue. Has anyone else encountered this, and how did you address it? Any insight or workaround to make the XML display correctly in the Azure DevOps test tab would be greatly appreciated.

I am open to use any other format if there is no work around for JUnit.

Thank you for your time and help.

  • 1. “When viewing the test failure report directly, the formatting appears correct” – Can you share a screenshot to let us know what the correct format you expect is? 2. “the formatting in the Azure DevOps test tab seems to ignore leading spaces in the output” – Please share a screenshot of the failed tests in Test tab.

    – 

  • @ZiyangLiu-MSFT I have edited the post and included information that you have requested. Thank you for your time.

    – 

Leave a Comment