Ant批量执行Jmeter脚本

Posted 哈哈

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Ant批量执行Jmeter脚本相关的知识,希望对你有一定的参考价值。

Ant+Jmeter+Jenkins集成详见:  http://www.cnblogs.com/leihaha/p/8398120.html

此处给出Ant批量执行jmeter脚本的build.xml代码:

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <project name="dycmm-performance-jmeter" default="run" basedir=".">
 3     <tstamp>
 4         <format property="time" pattern="yyyyMMddHHmm" />
 5     </tstamp>
 6     
 7     <!-- 定义jmeter相关信息:报告名称、jmeter目录地址、测试间隔时间 -->
 8     <property name="report.title" value="Dyoon dycmms Test Report" />
 9     <property name="jmeter-home" value="D:\\apache-jmeter-3.0" />
10     <property name="interval-time-in-seconds" value="20" />
11     
12     <!-- 定义相关目录 -->
13     <property name="runremote" value="false" />  <!--jmeter是否分布式-->
14     <property name="resultBase" value="Results" />
15     <property name="results.jtl" value="jtl" />
16     <property name="results.html" value="html" />
17     <property name="jmxs.dir" value="dycmms" />
18     
19     
20     <!-- HTML报告配置相关的jar包-->
21     <path id="xslt.classpath">
22         <fileset dir="./lib" includes="xalan*.jar" />
23         <fileset dir="./lib" includes="serializer*.jar" />
24     </path>
25     
26     <!-- 初始化:删除并重建结果目录-->
27     <target name="init">
28         <delete dir="${resultBase}/" />
29         <mkdir dir="${resultBase}/${results.jtl}" />
30         <mkdir dir="${resultBase}/${results.html}" />
31     </target>
32     
33     <target name="all-test" depends="init">    
34         <!-- antcontrib:support foreach by ant -->
35         <taskdef resource="net/sf/antcontrib/antlib.xml">
36             <classpath>
37                 <pathelement location="./lib/ant-contrib-1.0b3.jar" />
38             </classpath>
39         </taskdef>
40         
41         <foreach param="jmxfile" target="test" >
42             <fileset dir="${jmxs.dir}">
43                 <include name="*.jmx" />
44             </fileset>
45         </foreach>
46     </target>
47     
48     <target name="test">
49         <!--运行jmx脚本-->
50         <taskdef name="jmeter" 
51              classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask" />
52         <basename property="jmx.filename" file="${jmxfile}" suffix=".jmx" />
53         <echo message="---------- Processing ${jmxfile} -----------" />
54         <echo message="resultlogdir==${resultBase}/${results.jtl}" />
55         <jmeter jmeterhome="${jmeter-home}" 
56                 resultlogdir="${resultBase}/${results.jtl}"
57                 runremote="${runremote}"
58                 resultlog="${jmx.filename}.jtl"
59                 testplan="${jmxs.dir}/${jmx.filename}.jmx">
60             <jvmarg value="-Xincgc" />
61             <jvmarg value="-Xms1024m" />
62             <jvmarg value="-Xmx1024m" />
63             
64             <property name="jmeter.save.saveservice.output_format" value="xml" />
65         </jmeter>
66         
67         <sleep seconds="10"></sleep>
68         
69         <!--生成HTML报告-->
70         <tstamp><format property="report.datestamp" pattern="yyyy/MM/dd HH:mm" /></tstamp>
71         <xslt 
72             classpathref="xslt.classpath"
73             force="true"
74             in="${resultBase}/${results.jtl}/${jmx.filename}.jtl"
75             out="${resultBase}/${results.html}/${jmx.filename}.html"        
76             style="${jmeter-home}/extras/jmeter-results-detail-report_21.xsl">
77             <param name="dateReport" expression="${report.datestamp}" />
78             <param name="titleReport" expression="${report.title}:[${jmx.filename}]" />
79         </xslt>
80         
81         <echo message="Sleep ${interval-time-in-seconds} Seconds, and then start next Test; Please waiting..." />
82         <sleep seconds="${interval-time-in-seconds}"></sleep>    
83     </target>
84     
85     <target name="copy-images" depends="all-test">
86         <!--生成报告的时候,需要手动将相关的图片一起起拷贝至目标目录-->
87         <copy todir="${resultBase}/${results.html}">
88             <fileset dir="${jmeter-home}/extras">
89                 <include name="collapse.png" />
90                 <include name="expand.png" />
91             </fileset>
92         </copy>
93     </target>
94     
95     <target name="run" depends="all-test,copy-images" />
96 </project>

相关jar包放在build.xml同目录下的lib文件夹中

  

说明:

下面的代码中,如果下载的ant-contrib版本小于1.6时,代码需要变更为:

 <taskdef resource="net/sf/antcontrib/antcontrib.properties">
     <classpath>
            <pathelement location="./lib/ant-contrib-version.jar" />
      </classpath>
</taskdef>        

 

以上是关于Ant批量执行Jmeter脚本的主要内容,如果未能解决你的问题,请参考以下文章

ant批量执行Jmeter脚本

Jmeter 批量执行脚本之-----------Ant

Ant 批量执行jmeter 脚本

Ant 与jemter的结合--批量执行jmeter脚本

centos下怎么使用ant批量执行jmeter

jmeter持续集成化---jmeter+Ant+DOS构建执行脚本