ant呼叫jmeter時的build.xml
<?xml version="1.0" encoding="utf-8"?>
<project name="ant-jmeter-test" default="run" basedir=".">
<tstamp>
<format property="time" pattern="yyyyMMddhhmm" />
</tstamp>
<!-- 需要改成自己本地的 Jmeter 目錄-->
<property name="jmeter.home" value="D:\apache-jmeter-3.0" />
<!-- jmeter生成jtl格式的結果報告的路徑-->
<property name="jmeter.result.jtl.dir" value="D:\apache-jmeter-3.0\demo\report\jtl" />
<!-- jmeter生成html格式的結果報告的路徑-->
<property name="jmeter.result.html.dir" value="D:\apache-jmeter-3.0\demo\report\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="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}">
<!-- 宣告要執行的指令碼。"*.jmx"指包含此目錄下的所有jmeter指令碼-->
<testplans dir="D:\apache-jmeter-3.0\demo" includes="*.jmx" />
<!--<property name="jmeter.save.saveservice.output_format" value="xml"/>-->
</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>