一、ant安装与环境配置
1、配置jdk环境
2、配置ant,需要配置ant环境
ANT_HOME=D:\ant\apache-ant-1.10.1 (ant下载包解压路径,apache-ant-1.10.1需要的jdk1.8环境 )
CLASSPATH=%ANT_HOME%\lib
PATH=%ANT_HOME%\bin
说明:ant版本需要相匹配的jdk版本
验证:cmd中输入ant -v ,信息如下图,则代表配置成功
二、ant+jmeter实现批量执行jmter脚本
准备:
1.jmeter脚本准备
2.新建一个demo,把jmx脚本放进去
3.在demo下新建目录resultLog,log下新建两个子目录html,jtl
4.将 jmeter的extras目录中ant-jmeter-1.1.1.jar包拷贝至ant安装目录下的lib目录中
5.修改Jmeter的bin目录下jmeter.properties文件的配置:jmeter.save.saveservice.output_format=xml
html:存放生成的html报告
jtl:存放生成的jtl报告
build.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<project name="ant-jmeter-test" default="run" basedir=".">
<taskdef resource="net/sf/antcontrib/antlib.xml" />
<!-- (1)需要改成自己本地的 Jmeter 目录-->
<property name="jmeter.home" value="D:\jemter\apache-jmeter-3.0"/>
<property name="report.title" value="report"/>
<!-- (2)jmeter生成jtl格式的结果报告的路径-->
<property name="jmeter.result.jtl.dir" value="D:\jemter\apache-jmeter-3.0\demo\resultLog\jtl"/>
<!-- (3)jmeter生成html格式的结果报告的路径-->
<property name="jmeter.result.html.dir" value="D:\jemter\apache-jmeter-3.0\demo\resultLog\html"/>
<!-- 生成的报告的前缀 -->
<property name="ReportName" value="TestReport"/>
<property name="jmeter.result.jtlName" value="${jmeter.result.jtl.dir}/${ReportName}.jtl"/>
<property name="jmeter.result.htmlName" value="${jmeter.result.html.dir}/${ReportName}.html"/>
<target name="run">
<antcall target="test"/>
<antcall target="report"/>
<!--antcall target="mail"/-->
</target>
<target name="test">
<taskdef name="jmeter" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask"/>
<jmeter jmeterhome="${jmeter.home}" resultlog="${jmeter.result.jtlName}">
<!-- (4)build.xml的存放的路径-->
<testplans dir="D:\jemter\apache-jmeter-3.0\demo" includes="*.jmx"/>
<property name="jmeter.save.saveservice.output_format" value="xml"/>
</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-detail-report.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>
<!--target name="mail">
<for list="hanxm@thunisoft.com" param="tmp" >
<sequential>
<echo>message @{tmp}</echo>
<mail mailhost="smtp.thunisoft.com" mailport="25" ssl="false" subject="ant mail" messagemimetype="text/html" user="zhangjn" password="*******" tolist="@{tmp}">
<from address="zhangjn@thunisoft.com" />
<fileset dir="${jmeter.result.html.dir}