1.java安装,环境变量配置:https://www.jianshu.com/p/6505d11aecc3
2.jmeter安装,环境变量配置:https://blog.csdn.net/fangfeixinlingamp/article/details/79982215
3.ant安装,环境变量配置:https://blog.csdn.net/wanghjbuf/article/details/54773440
4.将\apache-jmeter-4.0\extras下的ant-jmeter-1.1.1.jar文件复制到H:\Interface_automation\apache-ant-1.10.5-bin\lib下。(这样在运行ant的时候才能启动jmeter)
5.修改Jmeter的bin目录下jmeter.properties文件的配置: jmeter.save.saveservice.output_format=xml
以及以下修改(主要为需要显示的结果,按实际需求去除前面的#)
legitimate values: none, first, all
jmeter.save.saveservice.assertion_results=none
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=false
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
Only available with HttpClient4
jmeter.save.saveservice.connect_time=true
jmeter.save.saveservice.samplerData=false
jmeter.save.saveservice.responseHeaders=false
jmeter.save.saveservice.requestHeaders=false
jmeter.save.saveservice.encoding=false
jmeter.save.saveservice.bytes=true
Only available with HttpClient4
jmeter.save.saveservice.sent_bytes=true
jmeter.save.saveservice.url=false
jmeter.save.saveservice.filename=false
jmeter.save.saveservice.hostname=false
jmeter.save.saveservice.thread_counts=true
jmeter.save.saveservice.sample_count=false
jmeter.save.saveservice.idle_time=true
6.在D:\apache-jmeter-4.0\apache-jmeter-4.0文件夹下新建report文件夹(用来放置运行结果,运行配置文件等)
7.在report文件夹下新建jtl,html,jiaoben文件夹,并将build.xml文件放在此文件夹下。
8.修改build.xml配置,如下:
<?xml version="1.0" encoding="UTF-8"?>
<project name="ant-jmeter-test" default="all" basedir=".">
<!-- 需要改成自己本地的 Jmeter 目录-->
<property name="jmeter.home" value="D:\apache-jmeter-4.0" />
<!-- 声明要运行的脚本。"*.jmx"指包含此目录下的所有jmeter脚本-->
<property name="jmeter.testplans.dir" value="D:\apache-jmeter-4.0\report\jiaoben" />
<!-- jmeter生成jtl格式的结果报告的路径-->
<property name="jmeter.result.jtl.dir" value="D:\apache-jmeter-4.0\report\jtl" />
<!-- jmeter生成html格式的结果报告的路径-->
<property name="jmeter.result.html.dir" value="D:\apache-jmeter-4.0\report\html" />
<!-- jmeter生成html格式的结果报告的模板-->
<property name="jmeter.result.style.dir" value="D:\apache-jmeter-4.0\report\demo" />
<!-- 生成的报告的前缀-->
<property name="ReportName" value="TestReport" />
<property name="jmeter.result.jtlName" value="${jmeter.result.jtl.dir}/report.jtl" />
<property name="jmeter.result.htmlName" value="${jmeter.result.html.dir}/report-details.html" />
<property name="lib.dir" value="${jmeter.home}/lib"/>
<path id="xslt.classpath">
<fileset dir="${lib.dir}" includes="xalan-*.jar"/>
<fileset dir="${lib.dir}" includes="serializer-*.jar"/>
</path>
<target name="all">
<antcall target="clean" />
<antcall target="run" />
<antcall target="report" />
<antcall target="xslt-report" />
</target>
<target name="clean">
<delete file="${jmeter.result.jtlName}"/>
</target>
<target name="run">
<taskdef name="jmeter" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask" />
<jmeter jmeterhome="${jmeter.home}" resultlog="${jmeter.result.jtlName}">
<testplans dir="${jmeter.testplans.dir}" includes="*.jmx" />
<property name="jmeter.save.saveservice.output_format" value="xml"/>
<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.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>
<target name="xslt-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.html.dir}/report-summary.html"
style="${jmeter.result.style.dir}/jmeter-results-detail-report_21.xsl">
<param name="dateReport" expression="${report.datestamp}"/>
</xslt>
</target>
<target name="report">
<xslt classpathref="xslt.classpath"
force="true"
in="${jmeter.result.jtlName}"
out="${jmeter.result.htmlName}"
style="${jmeter.result.style.dir}/jmeter-results-shanhe-me.xsl">
<!-- 因为上面生成报告的时候,不会将相关的图片也一起拷贝至目标目录,所以,需要手动拷贝 -->
<param name="showData" expression="${show-data}"/>
</xslt>
<copy todir="${jmeter.result.html.dir}">
<fileset dir="${jmeter.home}/extras">
<include name="collapse.png" />
<include name="expand.png" />
</fileset>
</copy>
</target>
</project>
9.在此文件夹下运行cmd,并输入ant,如运行结果如下,则ant配置成功:
10.安装jenkins,配置环境变量:
安装插件Ant Plugin,HTML Publisher plugin
11.新建工程
12.点击立即构建。
成功!!!!!!