Search code examples
jenkinsjunitjenkins-pluginsnewman

Jenkins test results analyzer is presenting duration wrong


I'm running a Jenkins job that's running some newman tests and is producing a junit test results file that looks like that:

<?xml version="1.0" encoding="UTF-8"?> <testsuites name="Basic Regression All"> <testsuite name="Login" id="02d5167b-ce9c-4ba4-9b24-e0a5c142768f" tests="2" time="628"> <testcase name="Successful Login"/> <testcase name="Auth Token is not null"/> </testsuite> <testsuite name="Account Summary" id="18773a24-2e3a-4c7d-99c3-921c4e41541b" tests="1" time="290"> <testcase name="Successfully Retreived Accounts"/> </testsuite> <testsuite name="Account Balances" id="d0817e78-8a25-4bc2-9301-3b4ef954600a" tests="1" time="337"> <testcase name="Successfully Retreived Balances"/> </testsuite> For some reason the time field is read by the "test results analyzer" plugin as seconds and not milliseconds as shown at the attached pic. Any clue on what's going on here would help. Also I'm using the latest version of both "test results analyzer" and junit, so if anyone knows of a better Jenkins plugin to use please share

Test Results


Solution

  • Ok, so from what I've read it seems that the culprit here is Newman (Postman CMD tool) rather than Test Results Analyzer. looking at this page here:

    https://www.ibm.com/support/knowledgecenter/en/SSQ2R2_9.5.0/com.ibm.rsar.analysis.codereview.cobol.doc/topics/cac_useresults_junit.html?_sm_au_=iVV1H1fVNH2HFqZH

    It seems that the Junit format has the "time" attribute in seconds rather then milliseconds. I.e. Newman produces: time="337" (as you can see above) where as Test Analyzer is expecting time="0.337"

    So added another build stage (Jenkins) that runs this little python script that converts the "time" attribute from milliseconds to seconds.

    import os
    import xml.etree.ElementTree as etree
    
    #print os.getcwd()
    os.chdir('path_to/tests')
    
    collection = os.environ['Collection']
    e = etree.parse(collection + '_results.xml').getroot()
    
    for atype in e.findall('testsuite'):
        duration=int((atype.get('time')))
        atype.set('time',str(duration/float(1000)))
    
    f = open('fixed.xml','w')
    print >> f, etree.tostring(e)
    

    and that fixed it

    UPDATE:

    Actually it turns out I had an outdated version on Newman running on the server.... Upgrading newman to the latest version (3.5.2) fixes that issue.... Oh well....