• jenkins,jmeter,ant持续集成


    1、安装 jenkins, jmeter, ant
     
    2、将 jmeter下extras中的 ant-jmeter-1.1.1.jar拷贝到ant的lib下面
    3、将 jmeter下collapse.png, expand.png, jmeter-result-detail-report_21.xsl拷贝到ant安装目录下 这些是生成测试报告的关键点
    4、将 jmeter下的build.xml文件拷贝到ant安装目录下,对build.xml的文件进行修改 
         建议将各种property name=**path 的value都改成绝对路径,明确的能查到具体地址
       
       

    <path id="jmeter.classpath">
    <pathelement location="/xxxx/xxx/apache-ant-1.9.6/lib/ant-jmeter-1.1.1.jar" />
    <!-- <fileset dir="/xxx/xxx/apache-ant-1.9.6">
    <include name="ant-jmeter*.jar"/>
    </fileset>
    -->
    </path>

        原来文件中使用的是fileset,但后来因为路径问题,实在找不到.jar包,故直接把jar包路径写死。
     
     在文件中增加了以下内容:

    <property name="jmeter.save.saveservice.response_data" value="true"/>
    <property name="jmeter.save.saveservice.samplerData" value="true"/>
    <property name="jmeter.save.saveservice.responseHeaders" value="true"/>
    <property name="jmeter.save.saveservice.requestHeaders" value="true"/>
    <property name="jmeter.save.saveservice.encoding" value="true"/>
    <property name="jmeter.save.saveservice.url" value="true"/>
    <property name="jmeter.save.saveservice.filename" value="true"/>
    <property name="jmeter.save.saveservice.hostname" value="true"/>
    <property name="jmeter.save.saveservice.thread_counts" value="true"/>
    <property name="jmeter.save.saveservice.sample_count" value="true"/>
    <property name="jmeter.save.saveservice.idle_time" value="true"/>
    <property name="jmeter.save.saveservice.output_format" value="xml"/>
    <property name="jmeter.save.saveservice.assertion_results" value="all"/>
    <property name="jmeter.save.saveservice.bytes" value="true"/>
    <property name="file_format.testlog" value="${format}"/>
    <property name="jmeter.save.saveservice.response_data.on_error" value="${funcMode}"/>

    5、改完这些内容后,可对jenkins进行配置

    http://jk.facebank.net.cn/configureTools/ 对jdk,ant等进行配置,指定build.xml具体的位置即可。

     
     
     
    附带一个全面的build.xml文件
     
    <?xml version="1.0" encoding="utf-8"?>
    <project default="all">
    <!-- Define your Jmeter Home & Your Report Title & Interval Time Between Test-->
    <property name="report.title" value="WebLoad Test Report"/>
    <property name="jmeter-home" location="D:workapache-jmeter-2.8" />
    <property name = "interval-time-in-seconds" value ="10"/>
    <!-- default path config, you can modify for your own requirement;Generally, you do not need to modify -->
    <property environment="env" />
    <property name="runremote" value="false"/>
    <property name="resultBase" value="results"/>
    <property name="results.jtl" value="jtl"/>
    <property name="results.html" value ="html"/>
    <property name="jmxs.dir"  value= "jmxs"/>
    <tstamp><format property="report.datestamp" pattern="yyyy-MM-dd-HH-mm-ss"/></tstamp>
    <property name="time" value="${report.datestamp}"/>
    
    <!--  Diffrent version of Jmeter has its own ant-jmeter.jar,Please input the right versioin -->
    <path id="ant.jmeter.classpath">
    <pathelement location="${jmeter-home}/lib/ant-jmeter-1.1.1.jar" />
    </path>
    <taskdef name="jmeter"
         classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask"
         classpathref="ant.jmeter.classpath" />
    <!-- just to support foreach by ant -->
    <taskdef resource="net/sf/antcontrib/antcontrib.properties" >
    <classpath>
        <pathelement location="./libs/ant-contrib-20020829.jar" />
    </classpath>
    </taskdef>
    
    <!-- use this config to generate html report; if not, may not display Min/Max Time in html-->
    <path id="xslt.classpath">
    <fileset dir="./libs" includes="xalan-2.7.1.jar"/>
    <fileset dir="./libs" includes="serializer-2.9.1.jar"/>
    </path>
    <!--运行之前首先创建临时结果文件夹-->
    <target name="create-folder">
    <delete dir="${resultBase}/temp"/>
    <mkdir dir="${resultBase}/temp/${results.jtl}" />
    <mkdir dir="${resultBase}/temp/${results.html}" />
    </target>
    
    <target name="all-test" depends="create-folder">
    <foreach  param="jmxfile" target="test" >
        <fileset dir="${jmxs.dir}">
            <include name="*.jmx" />
        </fileset>
    </foreach>
    </target>
    
    <target name="test" >
    <basename property="jmx.filename" file="${jmxfile}" suffix=".jmx"/>
    <echo message="---------- Processing ${jmxfile} -----------"/>
    <echo message="resultlogdir===${resultBase}/temp/${results.jtl}"/>
    <jmeter jmeterhome="${jmeter-home}" resultlogdir="${resultBase}/temp/${results.jtl}" runremote="${runremote}" resultlog="${jmx.filename}.jtl"
            testplan="${jmxs.dir}/${jmx.filename}.jmx">
        <jvmarg value="-Xincgc"/>
        <jvmarg value="-Xms1024m"/>
        <jvmarg value="-Xm1024m"/>
    
    </jmeter>
    <sleep seconds="20"></sleep>
    <!--Generate html report-->
    
    <xslt   in="${resultBase}/temp/${results.jtl}/${jmx.filename}.jtl"  
            out="${resultBase}/temp/${results.html}/${jmx.filename}.html"  classpathref="xslt.classpath"
            style="${jmeter-home}/extras/jmeter-results-report_21.xsl" >
        <param name="dateReport" expression="${report.datestamp}"/>
        <param name="showData" expression="n"/>
        <param name="titleReport" expression="${report.title}:[${jmx.filename}]"/>
    </xslt>
    
    <echo message="Sleep ${interval-time-in-seconds} Seconds, and then start next Test; Please waiting ......"/>
    <sleep seconds="${interval-time-in-seconds}"></sleep>
    </target>
    
    <target name="copy-images" depends="all-test">
    <copy file="${jmeter-home}/extras/expand.png" tofile="${results.html}/expand.png"/>
    <copy file="${jmeter-home}/extras/collapse.png" tofile="${results.html}/collapse.png"/>
    <copydir src="${resultBase}/temp" dest="${resultBase}/${report.datestamp}"/>
    <delete dir="${resultBase}/temp"/>
    </target>
    
    <target name="all" depends="all-test, copy-images" />
    </project>  
  • 相关阅读:
    本地服务器连接不上解决过程!!!
    delete语句与reference约束 FK_subplan_job_id冲突问题,导致job无法删除解决办法
    设置手动批量删除数据库相关进程
    生成10位由大小写字母和数字组成的随机激活码
    修改表中某个字段区分大小写
    SQL获取时间戳流水号
    TypeError: Object(...) is not a function
    vue 中使用setTimeout
    Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber
    微信小程序 指定tabBar打开某个tab
  • 原文地址:https://www.cnblogs.com/yingchen/p/5912502.html
Copyright © 2020-2023  润新知