实际上是jenkins驱动ant,ant驱动jenkins执行脚本操作

1.首先搭建jmeter环境

安装java,jmeter,ant并且配置环境变量

安装验证 

ant -v

2.ant中配置jmeter

将jmeter extras目录下的ant-jmeter-1.1.1.jar 文件拷贝到ant安装目录下的lib文件夹中

配置ant 编译文件 build.xml

<?xml version="1.0" encoding="UTF-8"?>
<project name="ant-jmeter-test" default="run" basedir=".">
    <!--    <taskdef resource="net/sf/antcontrib/antlib.xml"/>-->
    <tstamp>
        <format property="time" pattern="yyyyMMddhhmm"></format>
    </tstamp>
    <property name="jmeter.home" value="D:\apache-jmeter-3.2"/>
    <property name="report.title" value="report"/>
    <property name="jmeter.result.jtl.dir" value="D:\report\jtl"/>
    <property name="jmeter.result.html.dir" value="D:\report\html"/>
    <property name="ReportName" value="Report"/>
    <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="run">
        <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}">
            <testplans dir="D:aa\" includes="*.jmx"/>
            <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}"/>
        </jmeter>
    </target>
    <path id="xslt.classpath">
        <fileset dir="${jmeter.home}/lib" includes="xalan*.jar"/>
        <fileset dir="${jmeter.home}/lib" includes="serializer*.jar"/>
    </path>
    <target name="report">
        <tstamp>
            <format property="report.datestamp" pattern="yyyy/MM/dd HH:mm"/>
        </tstamp>
        <xslt classpathref="xslt.classpath"
              force="true"
              in="${jmeter.result.jtlName}"
              out="${jmeter.result.htmlName}"
              style="${jmeter.home}/extras/jmeter.results.shanhe.me.xsl">
            <param name="dateReport" expression="${report.datestamp}"/>
        </xslt>

        <copy todir="${jmeter.result.html.dir}">
            <fileset dir="${jmeter.home}/extras">
                <include name="collapse.png"/>
                <include name="expand.png"/>
            </fileset>
        </copy>
    </target>
    <path id="lib_classpath">
        <fileset dir="${basedir}/">
            <include name="mail*.jar"/>
            <include name="activation*.jar"/>
            <include name="commons-email*.jar"/>
            <include name="ant-contrib*.jar"/>
        </fileset>
    </path>
</project>

3.配置jmeter.properties

   配置jmeter报告输出格式为xml在jmeter根目录下jmeter.properties文件中修改jmeter.save.saveservice.output_format=csv 为jmeter.save.saveservice.output_format=xml,并去掉前面的注释符号#

使用明细模板(jmeter.results.shanhe.me.xsl)还需要以下内容

jmeter.save.saveservice.data_type=true
jmeter.save.saveservice.label=true
jmeter.save.saveservice.response_code=true
# response_data is not currently supported for CSV output
jmeter.save.saveservice.response_data=true
# Save ResponseData for failed samples
jmeter.save.saveservice.response_data.on_error=false
jmeter.save.saveservice.response_message=true
jmeter.save.saveservice.successful=true
jmeter.save.saveservice.thread_name=true
jmeter.save.saveservice.time=true
jmeter.save.saveservice.subresults=true
jmeter.save.saveservice.assertions=true
jmeter.save.saveservice.latency=true
jmeter.save.saveservice.connect_time=true
jmeter.save.saveservice.samplerData=true
jmeter.save.saveservice.responseHeaders=true
jmeter.save.saveservice.requestHeaders=true
jmeter.save.saveservice.encoding=false
jmeter.save.saveservice.bytes=true
jmeter.save.saveservice.url=true
jmeter.save.saveservice.filename=true
jmeter.save.saveservice.hostname=true
jmeter.save.saveservice.thread_counts=true
jmeter.save.saveservice.sample_count=true
jmeter.save.saveservice.idle_time=true

 

4.准备测试脚本数据

build配置文件放在与测试脚本同目录

5.执行测试      

命令行cd到build.xml文件所在目录,输入ant run ,执行测试

6.测试报告优化

jmeter自带报告(.\apache-jmeter-3.2\extras\jmeter-results-report_21)

优化版报告 jmeter.results.shanhe.me.xsl

仪表盘式报告  参考:https://blog.csdn.net/qq_39720249/article/details/85044581

 

至此,本地使用ant运行jmeter已无问题,请看下一篇,集成到jenkins

 

posted on 2019-07-16 11:01  浅草风铃  阅读(257)  评论(0编辑  收藏  举报
                                                                                                                                --------------------------------This is me!--------------------------------