1. gzyueqian
      18529173453
      首頁 > 新聞中心 > > 正文

      Ant+JMeter進(jìn)行Web應(yīng)用的穩(wěn)定性測試

      更新時間: 2007-05-18 14:56:13來源: 粵嵌教育瀏覽量:909


        Ant是一個快速開發(fā)的工具,類似Unix下的make,很方便的組織項目,編譯,打包,布署等。對于Ant的使用這里就不介紹了,若未使用過,可以在網(wǎng)上找到很多文章和例子。也可聯(lián)系我kui.yao@163.com
        
        JMeter也是Apache的一個開源工具,是一個比較流行的WEB應(yīng)用測試工具,當(dāng)然作為測試工具,也可以進(jìn)行其它測試,比如數(shù)據(jù)庫,JDBC等。其本身的使用,比如如何創(chuàng)建一個測試計劃,建立監(jiān)聽器,比如使用表格進(jìn)行結(jié)果查看,將測試結(jié)果記錄到文件中等,也不在這里介紹,如果不清楚,也可以聯(lián)系我kui.yao@163.com。
        
        由于JMeter本身主要用于性能測試,也即是峰值測試,同時在線的人數(shù)和系統(tǒng)壓力等。而在實際系統(tǒng)中還需要對“穩(wěn)定性”測試。比如根據(jù)的總量(如60000警情),平均間隔多久就會有一個 新警情發(fā)生,要求服務(wù)器連續(xù)工作24或7*24小時的情況進(jìn)行測試。這樣思想就是根據(jù)估計,間隔一定時間重復(fù)運行一個“測試計劃”達(dá)到此要求。
        
        1,使用ant進(jìn)行jmeter測試,同時利用xsl樣式查看結(jié)果。詳細(xì)可以參考文章。
        
        2,這里進(jìn)入本主題,利用ant進(jìn)行穩(wěn)定測試。
        
        a,這里我有一個http的測試web1.jmx,測試結(jié)果記錄到web1.jtl中。利用ant的build.xml文件可以是這樣的。
        
        <project name="antjmeter" default="run" basedir=".">
        <property name="out" value="."/>
        <target name="test">
        <taskdef
        name="jmeter"
        classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask"/>
        
        <jmeter
        jmeterhome="D:\ProgramFiles\jakarta-jmeter-2.1.1"
        testplan="${basedir}/web1.jmx"
        resultlog="${out}/web1.jtl">
        <jvmarg value="-Dgroup1.threads=10"/>
        </jmeter>
        <echo message="jmeter web1.jmx finished"/>
        </target>
        <target name="interval">
        <echo message="sleep 5 seconds"/>
        <sleep seconds="5"/>
        <echo message="continue"/>
        </target>
        <target name="tfile">
        <xslt
        in="${basedir}/web1.jtl"
        out="${basedir}/web1.html"
        style="${basedir}/jmeter-results-report.xsl"/>
        </target>
        <target name="run" depends="test,interval,tfile"/>
        </project>
        
        運行結(jié)果查看。
        
        b,從上面可以運行一次“測試計劃”,如果要連續(xù)運行24小時呢?其中加了一個sleep目的就是想在每次運行完后暫停一下。這個根據(jù)你的系統(tǒng)要求估算。
        
        c,從基本思想上大家可以想象,如果ant有l(wèi)oop或for的話,也可設(shè)定運行次數(shù)來達(dá)到這個目的。但是目前Ant沒有此功能。所以達(dá)不到。通過我查看文檔,其中有ant和antcall的task,是不是可以利用這個來達(dá)到目的呢?
        
        即build.xml中寫為
        
        <target name="test">
        <taskdef
        name="jmeter"
        classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask"/>
        
        <jmeter
        jmeterhome="D:\ProgramFiles\jakarta-jmeter-2.1.1"
        testplan="${basedir}/web1.jmx"
        resultlog="${out}/web1.jtl">
        <jvmarg value="-Dgroup1.threads=10"/>
        </jmeter>
        <echo message="jmeter web1.jmx finished"/>
        
        <antcall target="interval"/>
        
        <antcall target="test"/> <!--循環(huán)調(diào)用自已來達(dá)到持續(xù)運行的目的。-->
        <!--ant antfile="build.xml"/-->
        </target>
        
        結(jié)果是使用ant或是antCall都不行。錯誤如下:
        
        antcall運行報錯
        BUILD FAILED
        D:\ProgramFiles\jakarta-jmeter-2.1.1\mytest\web3\build.xml:18: antcall task call
        ing its own parent target.
        ant 運行報錯
        BUILD FAILED
        D:\ProgramFiles\jakarta-jmeter-2.1.1\mytest\web3\build.xml:19: ant task calling
        a target that depends on its parent target 'test'.
        
        d,不過從前者的結(jié)果看,是不能call its own。因此我將原target test一樣考貝一份取名test2。
        
        則在test中<antcall target="test2"/>,在test2中<antcall target="test"/>,這樣運行就可以達(dá)到
        
        我想要的連續(xù)測試的要求。
        
        3,只是這樣也有缺陷,因為這沒有編程功能,不能在之中加入比如測500次或測24小時后就不再antcall
        
        而結(jié)束的功能。所以要在你想停止的時候手動停止了。
        
        4,這樣xslt轉(zhuǎn)換就不能寫在這個功能中了,手動停止后再做xslt轉(zhuǎn)換或直接在xml中加入xsl顯示即可。
        
        D:\ProgramFiles\jakarta-jmeter-2.1.1\mytest\web3>ant
        Buildfile: build.xml
        
        test:
        [jmeter] Executing test plan: D:\ProgramFiles\jakarta-jmeter-2.1.1\mytest\web
        3\web1.jmx
        [jmeter] Created the tree successfully
        [jmeter] Starting the test
        [jmeter] Tidying up ...
        [jmeter] ... end of run
        [echo] jmeter web1.jmx finished
        
        interval:
        [echo] sleep 5 seconds
        [echo] continue
        
        test2:
        [jmeter] Executing test plan: D:\ProgramFiles\jakarta-jmeter-2.1.1\mytest\web
        3\web1.jmx
        [jmeter] Created the tree successfully
        [jmeter] Starting the test
        [jmeter] Tidying up ...
        [jmeter] ... end of run
        [echo] jmeter web1.jmx finished
        
        interval:
        [echo] sleep 5 seconds
        [echo] continue
        
        test:
        [jmeter] Executing test plan: D:\ProgramFiles\jakarta-jmeter-2.1.1\mytest\web
        3\web1.jmx
        [jmeter] Created the tree successfully
        [jmeter] Starting the test
        [jmeter] Tidying up ...
        [jmeter] ... end of run
        [echo] jmeter web1.jmx finished
        
        interval:
        [echo] sleep 5 seconds
        [echo] continue
        
        test2:
        [jmeter] Executing test plan: D:\ProgramFiles\jakarta-jmeter-2.1.1\mytest\web
        3\web1.jmx
        [jmeter] Created the tree successfully
        [jmeter] Starting the test
        [jmeter] Tidying up ...
        [jmeter] ... end of run
        [echo] jmeter web1.jmx finished
        
        interval:
        [echo] sleep 5 seconds
        [echo] continue
        
        test:
        [jmeter] Executing test plan: D:\ProgramFiles\jakarta-jmeter-2.1.1\mytest\web
        3\web1.jmx
        [jmeter] Created the tree successfully
        [jmeter] Starting the test
        [jmeter] Tidying up ...
        [jmeter] ... end of run
        [echo] jmeter web1.jmx finished
        
        interval:
        [echo] sleep 5 seconds
        [echo] continue
        
        test2:
        [jmeter] Executing test plan: D:\ProgramFiles\jakarta-jmeter-2.1.1\mytest\web
        3\web1.jmx
        [jmeter] Created the tree successfully
        [jmeter] Starting the test
        [jmeter] Tidying up ...
        [jmeter] ... end of run
        [echo] jmeter web1.jmx finished
        
        interval:
        [echo] sleep 5 seconds
        [echo] continue
        
        test:
        [jmeter] Executing test plan: D:\ProgramFiles\jakarta-jmeter-2.1.1\mytest\web
        3\web1.jmx
        [jmeter] Created the tree successfully
        [jmeter] Starting the test
        [jmeter] Tidying up ...
        [jmeter] ... end of run
        [echo] jmeter web1.jmx finished
        
        interval:
        [echo] sleep 5 seconds
        [echo] continue
        
        test2:
        [jmeter] Executing test plan: D:\ProgramFiles\jakarta-jmeter-2.1.1\mytest\web
        3\web1.jmx
        [jmeter] Created the tree successfully
        [jmeter] Starting the test
        [jmeter] Tidying up ...
        [jmeter] ... end of run
        [echo] jmeter web1.jmx finished
        
        interval:
        [echo] sleep 5 seconds
        [echo] continue
        
        test:
        [jmeter] Executing test plan: D:\ProgramFiles\jakarta-jmeter-2.1.1\mytest\web
        3\web1.jmx
        [jmeter] Created the tree successfully
        [jmeter] Starting the test
        [jmeter] Tidying up ...
        [jmeter] ... end of run
        [echo] jmeter web1.jmx finished
        
        interval:
        [echo] sleep 5 seconds
        [echo] continue
        
        test2:
        [jmeter] Executing test plan: D:\ProgramFiles\jakarta-jmeter-2.1.1\mytest\web
        3\web1.jmx
        [jmeter] Created the tree successfully
        [jmeter] Starting the test
        [jmeter] Tidying up ...
        [jmeter] ... end of run
        [echo] jmeter web1.jmx finished
        
        interval:
        [echo] sleep 5 seconds
        [echo] continue
        
        test:
        [jmeter] Executing test plan: D:\ProgramFiles\jakarta-jmeter-2.1.1\mytest\web
        3\web1.jmx
        [jmeter] Created the tree successfully
        [jmeter] Starting the test
        [jmeter] Tidying up ...
        [jmeter] ... end of run
        [echo] jmeter web1.jmx finished
        
        interval:
        [echo] sleep 5 seconds
        終止批處理操作嗎(Y/N)? y
        
        D:\ProgramFiles\jakarta-jmeter-2.1.1\mytest\web3>
        
        e,綜合,可以使用此方法來達(dá)要求。當(dāng)你想停止測試時,則手動停止即可。查看上面的這個build
        <!-- Simple Ant Jmeter test-->
        <project name="antjmeter" default="run" basedir=".">
        <property name="out" value="."/>
        <target name="test">
        <taskdef
        name="jmeter"
        classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask"/>
        
        <jmeter
        jmeterhome="D:\ProgramFiles\jakarta-jmeter-2.1.1"
        testplan="${basedir}/web1.jmx"
        resultlog="${out}/web1.jtl">
        <jvmarg value="-Dgroup1.threads=10"/>
        </jmeter>
        <echo message="jmeter web1.jmx finished"/>
        
        <antcall target="interval"/>
        
        <antcall target="test2"/>
        <!--ant antfile="build.xml"/-->
        </target>
        <!--for execute target test many times,copy the target test
        to target test2-->
        <target name="test2">
        <taskdef
        name="jmeter"
        classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask"/>
        
        <jmeter
        jmeterhome="D:\ProgramFiles\jakarta-jmeter-2.1.1"
        testplan="${basedir}/web1.jmx"
        resultlog="${out}/web1.jtl">
        <jvmarg value="-Dgroup1.threads=10"/>
        </jmeter>
        <echo message="jmeter web1.jmx finished"/>
        
        <antcall target="interval"/>
        
        <antcall target="test"/>
        <!--ant antfile="build.xml"/-->
        
        </target>
        
        <target name="interval">
        <echo message="sleep 5 seconds"/>
        <sleep seconds="5"/>
        <echo message="continue"/>
        </target>
        <target name="tfile">
        <xslt
        in="${basedir}/web1.jtl"
        out="${basedir}/web1.html"
        style="${basedir}/jmeter-results-detail-report.xsl"/>
        </target>
        <target name="run" depends="test"/>
        </project>

      免費預(yù)約試聽課

      亚洲另类欧美综合久久图片区_亚洲中文字幕日产无码2020_欧美日本一区二区三区桃色视频_亚洲AⅤ天堂一区二区三区

      
      

      1. 亚洲AV成人无遮挡网站在线观看 | 亚洲日韩在线精品第一品 | 香蕉精品高清在线观看视频 | 一本大道香蕉在线精品亚洲 | 亚洲中文字幕精品久久久久久 | 午夜国产理论片中文飘花 |