您还未登录! 登录 | 注册 | 帮助  

您的位置: 首页 > 软件测试工具 > 性能测试工具 > 正文

使用ant来调用Jmeter,并定制运行时参数

发表于:2017-01-09 作者:网络转载 来源:

  为了应对不同的运行需求(主要是不同的线程数),以及可能的变化(host ip),在nongui运行时我对ant build.xml进行了一些修改
  1. log目录备份与运行前清除

 

<tstamp> <format property="time.stamp" pattern="HHmmss_yyyyMMdd"/> </tstamp> <property name="bak.dir" value="c:/apache-jmeter-2.10/bin/testresult/${time.stamp}" /> <property name="result.dir" value="c:/apache-jmeter-2.10/bin/testresult" /> <property name="jmeter.extra" value="c:/apache-jmeter-2.10/extras" /> <target name="clean" depends=""> <delete verbose="true"> <fileset dir="${result.dir}"> <include name="*.csv" /> <include name="*.jtl" /> </fileset> <fileset dir="${jmeter.extra}"> <include name="*.jtl" /> <include name="*.log" /> </fileset> </delete> </target> <target name="bak"> <copy todir="${bak.dir}" verbose="true"> <fileset dir="${result.dir}"> <include name="*.csv" /> <include name="*.jtl" /> </fileset> <fileset dir="${jmeter.extra}"> <include name="*.jtl" /> <include name="*.log" /> </fileset> </copy> </target>

 

  2. 传参定制jmeter run

 


<target name="run" depends="clean"> <mkdir dir="${bak.dir}" /> <property name="run.log" value="${bak.dir}/${th}_${loop}.log"/> <echo message="${run.log}"/> <record name="${run.log}"/> <echo>funcMode = ${funcMode}</echo> <delete file="${testpath}/${test}.html" /> <echo message="server: ${host}:${port}"/> <echo message="threads = ${th}"/> <echo message="loops   = ${loop}"/> <jmeter jmeterhome="${jmeter.home}" testplan="${testpath}/${test}.jmx" resultlog="${testpath}/${test}.jtl" jmeterlogfile="${testpath}/${test}.log" > <jvmarg value="-L jmeter=DEBUG"/> <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}" /> <property name="request.threads" value="${th}" /> <property name="request.threads.loop" value="${loop}" /> <property name="test.host" value="${host}" /> <property name="test.port" value="${port}" /> <property name="loadtest.rampUp" value="${ramp}" /> <property name="request.config" value="${config}" /> </jmeter> <antcall target="bak" /> </target>

 

  为了实现定制的目的,jmx文件里也要有一些对应的改变
  3. 我有多个jmx文件要运行,用了ant的 antcontrib,实现循环

 

<taskdef resource="net/sf/antcontrib/antlib.xml" /> <property file="./api_build.properties" /> <target name="apirun" depends="clean"> <mkdir dir="${bak.dir}" /> <property name="run.log" value="${bak.dir}/${th}_${loop}.log" /> <echo message="${run.log}" /> <record name="${run.log}" /> <echo>funcMode = ${funcMode}</echo> <delete file="${testpath}/${test}.html" /> <echo message="server: ${host}:${port}" /> <echo message="threads = ${th}" /> <echo message="loops   = ${loop}" /> <for list="${perf.apis}" param="api"> <sequential> <echo message="Now start the testing of API: @{api}" /> <jmeter jmeterhome="${jmeter.home}" testplan="${testpath}/${test}.jmx" resultlog="${testpath}/${test}.jtl" jmeterlogfile="${testpath}/${test}.log"> <jmeterarg value="-L jmeter=DEBUG" /> <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}" /> <property name="request.threads" value="${th}" /> <property name="request.threads.loop" value="${loop}" /> <property name="test.host" value="${host}" /> <property name="test.port" value="${port}" /> <property name="loadtest.rampUp" value="${ramp}" /> <property name="request.config" value="${config}" /> <property name="api" value="@{api}" /> </jmeter> </sequential> </for> <antcall target="bak" /> </target>

  在api_build.properties中写上 perf.apis=xxx,xxx,xxx,xxx于是可以按顺序执行