Jmeter+ant +Jenkins

作者: 望月成三人 | 来源:发表于2016-07-01 17:01 被阅读1003次
    • 怎么使用jmeter自行百度
    • 安装ant

    配置ant

    主要是配置build.xml

    <?xml version="1.0" encoding="UTF-8"?>
    
    <project name="ant-jmeter-test" default="all" basedir=".">
        <tstamp>
            <format property="time" pattern="yyyyMMddhhmm" />
        </tstamp>
        <!-- 需要改成自己本地的 Jmeter 目录-->
        <property name="jmeter.home" value="F:\xxxxx\Jmeter" />
        <!-- jmeter生成jtl格式的结果报告的路径-->
        <property name="jmeter.result.jtl.dir" value="F:\xxxxx\resultLog\jtl" />
        <!-- jmeter生成html格式的结果报告的路径-->
        <property name="jmeter.result.html.dir" value="F:\xxxxx\resultLog\html" />
        <!-- 生成的报告的前缀->
        <property name="ReportName" value="TestReport" />
        <property name="jmeter.result.jtlName" value="${jmeter.result.jtl.dir}/${ReportName}${time}.jtl" />
        <property name="jmeter.result.htmlName" value="${jmeter.result.html.dir}/${ReportName}${time}.html" />
    
        <target name="all">
            <antcall target="test" />
            <antcall target="report" />
        </target>
    
        <target name="test">
            <taskdef name="jmeter" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask" />
            <jmeter jmeterhome="${jmeter.home}" resultlog="${jmeter.result.jtlName}">
                <!-- 声明要运行的脚本。"*.jmx"指包含此目录下的所有jmeter脚本-->
                <testplans dir="D:\test_case_path" includes="*.jmx" />
            </jmeter>
        </target>
    
        <target name="report">
            <xslt in="${jmeter.result.jtlName}"
                  out="${jmeter.result.htmlName}"
                  style="${jmeter.home}/extras/jmeter-results-detail-report_21.xsl" />
    
            <!-- 因为上面生成报告的时候,不会将相关的图片也一起拷贝至目标目录,所以,需要手动拷贝 -->
            <copy todir="${jmeter.result.html.dir}">
                <fileset dir="${jmeter.home}/extras">
                    <include name="collapse.png" />
                    <include name="expand.png" />
                </fileset>
            </copy>
        </target></project>
    
    

    Jenkins配置

    • Jenkins 上安装 “Publish performance test result report” ,“Publish HTML reports” 的插件,配置一下。

    ant的配置

    Paste_Image.png
    运行效果如下: Paste_Image.png

    错误解决方案

    发现jenkins上性能图显示不出来

    解决方案:

    • Jmeter/bin 下将 jmeter.properties 中
    • jmeter.save.saveservice.output_format=csv的csv改成xml
      ji

    结果如下

    Paste_Image.png

    出现报错日志

    Started by user anonymous
    Building in workspace C:\Users\Administrator.jenkins\jobs\我的测试\workspace
    [testCase] $ cmd.exe /C '"ant.bat -file build.xml && exit %%ERRORLEVEL%%"'
    Buildfile: E:\apps\jmeter\testCase\build.xml
    all:
    test:
    [jmeter] Executing test plan: E:\apps\jmeter\testCase\web.jmx ==> E:\apps\jmeter\resultLog\jtl\TestReport201506080830.jtl
    [jmeter] Creating summariser <summary>
    [jmeter] Created the tree successfully using E:\apps\jmeter\testCase\web.jmx
    [jmeter] Starting the test @ Mon Jun 08 20:30:19 CST 2015 (1433766619320)
    [jmeter] Waiting for possible shutdown message on port 4445
    [jmeter] summary = 10 in 1.1s = 8.8/s Avg: 190 Min: 141 Max: 254 Err: 0 (0.00%)
    [jmeter] Tidying up ... @ Mon Jun 08 20:30:20 CST 2015 (1433766620505)
    [jmeter] ... end of run
    report:
    [xslt] Processing E:\apps\jmeter\resultLog\jtl\TestReport201506080830.jtl to E:\apps\jmeter\resultLog\html\TestReport201506080830.html
    [xslt] Loading stylesheet D:\app\apache-jmeter-2.13\extras\jmeter-results-detail-report_21.xsl
    BUILD SUCCESSFUL
    Total time: 2 seconds
    Performance: Percentage of errors greater or equal than 1% sets the build as unstable
    Performance: Percentage of errors greater or equal than 2% sets the build as failure
    Performance: Recording JMeter reports '/apps/jmeter/resultLog/jtl/*.jtl'
    Performance: no JMeter files matching '/apps/jmeter/resultLog/jtl/*.jtl' have been found. Has the report generated?. Setting Build to FAILURE
    Build step 'Publish Performance test result report' changed build result to FAILURE
    Finished: FAILURE
    我确定我的jtl文件目录是没有错的
    

    终于解决了

    • 根据日志文件报错,发现工作目录为:Building in workspace C:\Users\Administrator.jenkins\jobs\我的测试\workspace
      然而我的日志文件却在e盘,于是我构建了一个shell 命名,把e盘的日志文件收到复制到工作目录:cd $WORKSPACEcp -r E:/apps/jmeter/resultLog/* .
      我的配置的JMeter Report files: */jtl/.jtl

      再次运行:

    Paste_Image.png
    但是还有有点问题就是默认列表进来显示的数据为空图片,要点击进去才能看到具体的某一个图片
    Paste_Image.png

    解决方式:
    [https://issues.jenkins-ci.org/browse/JENKINS-27100]
    插件的bug,有老外已经修复,直接下载了替换即可

    生成的报告没有min和max的time的时间,显示的为NaN,但是在执行命名过程中是可以看到max和min的时间

    直接在build.xml加入以下几行就解决了:

    <!-- use this config to generate html report; if not, may not display Min/Max Time in html-->
    <path id="xslt.classpath">
    <fileset dir="${jmeter.home}/lib" includes="xalan-2.7.2.jar"/>
    <fileset dir="${jmeter.home}/lib" includes="serializer-2.7.2.jar"/>
    </path>
    

    实际操作下来,并没有解决,问题依旧存在。
    多次尝试后发现,仅需要从Jmeter的lib包里把xalan-2.7.2.jar和serializer-2.7.2.jar copy到Ant的lib包里即可,不用修改build.xml

    相关文章

      网友评论

        本文标题:Jmeter+ant +Jenkins

        本文链接:https://www.haomeiwen.com/subject/fjafjttx.html