build.xml 文件内容 --执行单个脚本
<?xml version="1.0"?>
<project name="ant-jmeter" default="all">
<description>
Sample build file for use with ant-jmeter.jar <!-- 基于 ant-jmeter.jar 的构建文件模板 -->
See http://www.programmerplanet.org/pages/projects/jmeter-ant-task.php
To run a test and create the output report:<!-- 执行一个测试,并生成测试报告 -->
ant -Dtest=script
To run a test only: <!-- 只执行一个测试,不生成测试报告 -->
ant -Dtest=script run
To run report on existing test output <!--执行.jtl文件生成测试报告(不执行测试) -->
ant -Dtest=script report
The "script" parameter is the name of the script without the .jmx suffix. <!-- 参数script 是测试脚本的名字,不带.jmx后缀-->
Additional options:
<!-- 待解决 -->
-Dshow-data=y - include response data in Failure Details
<!--指定测试脚本所在路径,如果不指定则使用当前文件中配置的路径,默认为 user.dir -->
-Dtestpath=xyz - path to test file(s) (default user.dir).
N.B. Ant interprets relative paths against the build file
<!-- 指定 Jmeter 安装目录,如果不指定则使用当前文件中配置的目录,默认为 ${basedir}/.. -->
-Djmeter.home=.. - path to JMeter home directory (defaults to parent of this build file)
<!-- 指定测试报告的 title-->
-Dreport.title="My Report" - title for html report (default is 'Load Test Results')
</description>
<property name="testpath" value="F:\demo"/> <!-- default values is '${user.dir}' ,测试脚本存放的路径 modified by mrbai-->
<property name="jmeter.home" value="E:\jmeter"/> <!-- default value is '${basedir}/..',Jmeter安装路径 modified by mrbai-->
<property name="report.title" value="一个小小的测试"/><!--default value is 'Load Test Results' modified by mrbai -->
<!-- Name of test (without .jmx) -->
<property name="test" value="test"/> <!-- 要执行的测试脚本 -->
<!-- Should report include response data for failures? -->
<property name="show-data" value="n"/>
<property name="format" value="2.1"/>
<condition property="style_version" value="_21">
<equals arg1="${format}" arg2="2.1"/>
</condition>
<condition property="funcMode">
<equals arg1="${show-data}" arg2="y"/>
</condition>
<condition property="funcMode" value="false">
<not>
<equals arg1="${show-data}" arg2="y"/>
</not>
</condition>
<!-- Allow jar to be picked up locally --> <!-- 允许调用的本地jar文件 -->
<path id="jmeter.classpath">
<fileset dir="${basedir}">
<include name="ant-jmeter*.jar"/>
</fileset>
</path>
<taskdef
name="jmeter"
classpathref="jmeter.classpath"
classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask"/>
<target name="all" depends="run,report"/>
<target name="run">
<echo>funcMode = ${funcMode}</echo>
<delete file="${testpath}/html/${test}.html"/> <!-- 先把旧的html文件删除 -->
<jmeter
jmeterhome="${jmeter.home}"
testplan ="${testpath}/${test}.jmx"
resultlog="${testpath}/jtl/${test}.jtl"> <!-- .jtl文件输出位置 -->
<!--jvm和Jmeter参数设置 -->
<jvmarg value="-Xincgc"/>
<jvmarg value="-Xmx128m"/>
<jvmarg value="-Dproperty=value"/>
<jmeterarg value="-qextra.properties"/>
<!-- Force suitable defaults -->
<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>
<property name="lib.dir" value="${jmeter.home}/lib"/>
<!-- Use xalan copy from JMeter lib directory to ensure consistent processing with Java 1.4+ -->
<path id="xslt.classpath">
<fileset dir="${lib.dir}" includes="xalan*.jar"/>
<fileset dir="${lib.dir}" includes="serializer*.jar"/>
</path>
<target name="report" depends="xslt-report,copy-images">
<echo>Report generated at ${report.datestamp}</echo>
</target>
<target name="xslt-report" depends="_message_xalan">
<tstamp><format property="report.datestamp" pattern="yyyy/MM/dd HH:mm"/></tstamp>
<xslt
classpathref="xslt.classpath"
force="true"
in="${testpath}/jtl/${test}.jtl"
out="${testpath}/html/${test}.html"
style="${basedir}/jmeter-results-detail-report${style_version}.xsl">
<param name="showData" expression="${show-data}"/>
<param name="titleReport" expression="${report.title}"/>
<param name="dateReport" expression="${report.datestamp}"/> <!-- 根据.jtl文件生成html-->
</xslt>
</target>
<!-- Copy report images if needed --> <!-- 必要图片的相关信息-->
<target name="copy-images" depends="verify-images" unless="samepath">
<copy file="${basedir}/expand.png" tofile="${testpath}/expand.png"/>
<copy file="${basedir}/collapse.png" tofile="${testpath}/collapse.png"/>
</target>
<target name="verify-images">
<condition property="samepath">
<equals arg1="${testpath}" arg2="${basedir}" />
</condition>
</target>
<!-- Check that the xalan libraries are present -->
<condition property="xalan.present">
<and>
<!-- No need to check all jars; just check a few -->
<available classpathref="xslt.classpath" classname="org.apache.xalan.processor.TransformerFactoryImpl"/>
<available classpathref="xslt.classpath" classname="org.apache.xml.serializer.ExtendedContentHandler"/>
</and>
</condition>
<target name="_message_xalan" unless="xalan.present">
<echo>Cannot find all xalan and/or serialiser jars</echo>
<echo>The XSLT formatting may not work correctly.</echo>
<echo>Check you have xalan and serializer jars in ${lib.dir}</echo>
</target>
</project>