Using gtest in jenkins

前端 未结 6 1895
情话喂你
情话喂你 2020-12-24 12:35

I successfully run my unit test with google test in Jenkins, but I don\'t know how to show the .xml file generated by gtest. It is said that gtest satisfies the JUnit format

6条回答
  •  星月不相逢
    2020-12-24 12:50

    Fraser's answer is good and you need some extra processing to convert the gtest XML to proper JTest format.

    First you ask gtest to output the result to XML using:

    mygtestapp --gtest_output=xml:gtestresults.xml
    

    Then in a script you need to add extra elements to properly flag skipped tests as such. Jenkin's JTest processor requires that a skipped test contains the element and not just setting status to "notrun":

    awk '{ if ($1 == ""; else print $0;}' gtestresults.xml > gtestresults-skipped.xml
    mv gtestresults.xml gtestresults.off
    

    If running this on a windows batch file, put the awk action inside a file to avoid problems with the quotes. awk.progfile:

    { if ($1 == ""; else print $0;}
    

    And create add in your bat file:

    awk -f awk.progfile gtestresults.xml > gtestresults-skipped.xml
    

    Lastly you point the JTest processor as a Post-Build step to read the converted XML:

    # Publish JUnit Test Result Report
    Test Report XMLs: gtestresults-skipped.xml
    

提交回复
热议问题