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于是可以按顺序执行