zoukankan      html  css  js  c++  java
  • 使用ant来调用jmeter,并定制运行时参数

    为了应对不同的运行需求(主要是不同的线程数),以及可能的变化(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于是可以按顺序执行


    4. 接下来准备搞一下report了,准备用python来做,完事后补上
  • 相关阅读:
    iOS动画之模拟音量振动条
    LeetCode Reverse Linked List
    Android使用BroadCastRecevier广播实现接收短信,并利用Toast弹出显示内容
    Python+Django+SAE系列教程16-----cookie&amp;session
    初识MVC之建项
    【Android 系统开发】使用 Source InSight 阅读 Android 源代码
    ym—— Android网络框架Volley(终极篇)
    俯视数据库系统原理
    hdu 1269 迷宫城堡
    2014年湖北省TI杯大学生电子设计竞赛论文格式
  • 原文地址:https://www.cnblogs.com/yeyong/p/3906372.html
Copyright © 2011-2022 走看看