build.xml

<?xml version="1.0" encoding="utf-8" ?>
    Sample build file for use with 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
    ant -Dtest=script report

The "script" parameter is the name of the script without the .jmx suffix.

Additional options:
    -Dshow-data=y - include response data in Failure Details
    -Dtestpath=xyz - path to test file(s) (default user.dir).
                     N.B. Ant interprets relative paths against the build file
    -Djmeter.home=.. - path to JMeter home directory (defaults to parent of this build file)
    -Dreport.title="My Report" - title for html report (default is 'Load Test Results')
</description>
<!--指定一个时间变量叫time,格式为yyyymmddHHmmss -->
<tstamp> 
	<format property="time" pattern="yyyyMMddHHmm" />
</tstamp>
<!--在ant中,一个property标签表示定义一个ant变量or属性,根据需要添加即可。 -->
<!--指定jmeter的路径 -->
<property name="jmeter.home" value="E:\Program Files\drver\Jmeter\apache-jmeter-3.2"/>
<property name="report.title" value="星野学习自定义接口测试报告"/>
<property name="result.filepath" value="E:\report\ant"/>
<property name="testplan.home" value="E:\Software\vip"/>
<property name="result.jtlname" value="${result.filepath}\jtl\${report.title}${time}.jtl"/>
<property name="result.htmlname" value="${result.filepath}\html\${report.title}${time}.html"/>


<!-- 用来指定ant与jmeter集成所需要的jar包,是由jmeter提供的,默认存放在jmeter的extras目录下 -->
<path id="jmeter.classpath">
    <fileset dir="${jmeter.home}\extras">
      <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">

    <!--  为了防止追加到已有的文件,所以先删除 
		<delete file="${testpath}/${test}.html"/>
	-->
	
	<!--核心任务,指定运行的jmeter的版本jmeterhome,testplan指定要运行的脚本。可以是*.jmx,表示执行所有jmx文件。不过弊端是会写入一个结果文件。也可以通过添加多个jmeter标签的方式来执行多个jmx脚本。
	resultlog是用来指定存放运行结果的jtl的文件。相当于命令行-l的作用。
	-->
	
	<!-- 如果要一次性执行多个jmeter脚本,则可以使用一下属性 testplans dir="xxx" includes="*.jmx" -->
    <jmeter
        jmeterhome="${jmeter.home}"
        resultlog="${result.jtlname}">
		<testplans dir="${testplan.home}" includes="*.jmx" />
    <!--
        <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"/>
    </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">
</target>

<!--  生成报告,通过in属性指定jtl结果文件,out指定生成的html文件,style指的是报告模板-->
<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="${result.jtlname}"
        out="${result.htmlname}"
        style="${jmeter.home}/extras/jmeter-results-detail-report_21.xsl">
        <param name="showData" expression="${show-data}"/>
        <param name="titleReport" expression="${report.title}"/>
        <param name="dateReport" expression="${report.datestamp}"/>
    </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>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值