【问题标题】:Jenkins test results analyzer is presenting duration wrongJenkins 测试结果分析器显示持续时间错误
【发布时间】:2017-05-08 07:14:11
【问题描述】:

我正在运行一个 Jenkins 作业,该作业正在运行一些 newman 测试,并正在生成一个如下所示的 junit 测试结果文件:

<?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> 由于某种原因,“测试结果分析器”插件将时间字段读取为秒而不是毫秒,如附图所示。 任何关于这里发生的事情的线索都会有所帮助。 此外,我正在使用“测试结果分析器”和 junit 的最新版本,所以如果有人知道更好的 Jenkins 插件可以使用,请分享

【问题讨论】:

    标签: jenkins junit jenkins-plugins newman


    【解决方案1】:

    好的,所以从我读到的内容看来,这里的罪魁祸首是 Newman(邮递员 CMD 工具)而不是测试结果分析器。在这里查看此页面:

    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

    Junit 格式似乎具有以秒为单位的“时间”属性,而不是毫秒。 IE。 Newman 产生: time="337" (如您在上面看到的)其中测试分析器期望 time="0.337"

    因此添加了另一个构建阶段 (Jenkins),它运行这个小 Python 脚本,将“时间”属性从毫秒转换为秒。

    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)
    

    然后解决了它

    更新:

    实际上,我在服务器上运行的 Newman 版本过时...... 哦,好吧....

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-29
      相关资源
      最近更新 更多