一尿赚、環(huán)境準(zhǔn)備:
1啊易、Jdk1.6或以上:http://www.oracle.com/technetwork/java/javase/downloads/index.html
命令行輸入:java -version,出現(xiàn)如下提示說(shuō)明安裝成功
2统抬、ANT下載:http://ant.apache.org/bindownload.cgi
命令行輸入:ant -v匪蝙,出現(xiàn)如下提示說(shuō)明安裝成功
3、Jmeter下載:http://jmeter.apache.org/download_jmeter.cgi
4吓著、將?jmeter的extras目錄中ant-jmeter-1.1.1.jar包拷貝至ant安裝目錄下的lib目錄中
5、修改Jmeter的bin目錄下jmeter.properties文件的配置:jmeter.save.saveservice.output_format=xml
二送挑、Jmeter腳本:
1绑莺、如何編寫(xiě)腳本請(qǐng)參見(jiàn):http://www.cnblogs.com/puresoul/p/4740436.html
2、腳本目錄:D:\apache-jmeter-2.13\demo
3惕耕、腳本內(nèi)容:
測(cè)試百度.jmx Google1.jmx
三纺裁、build.xml代碼:
四、運(yùn)行腳本:
1司澎、cmd進(jìn)入腳本目錄:D:\apache-jmeter-2.13\demo
2欺缘、輸入:ant ?或 ant run(run為build.xml中的task名),執(zhí)行結(jié)果:
D:\apache-jmeter-2.13\demo>ant
Buildfile: build.xml
all:
test:
[jmeter] Executing test plan: D:\apache-jmeter-2.13\demo\Google1.jmx ==> D:\apache-jmeter-2.13\demo\report\jtl\TestReport201509141114.jtl
[jmeter] Creating summariser[jmeter] Created the tree successfully using D:\apache-jmeter-2.13\demo\Google1.jmx
[jmeter] Starting the test @ Mon Sep 14 23:14:32 CST 2015 (1442243672984)
[jmeter] Waiting for possible shutdown message on port 4445
[jmeter] summary +? ? ? 1 in? ? 1s =? ? 1.9/s Avg:? 248 Min:? 248 Max:? 248 Err:? ? 1 (100.00%) Active: 1 Started: 1 Finished: 0
[jmeter] summary +? ? ? 5 in? ? 1s =? ? 7.8/s Avg:? 119 Min:? 107 Max:? 137 Err:? ? 0 (0.00%) Active: 0 Started: 1 Finished: 1
[jmeter] summary =? ? ? 6 in? 1.2s =? ? 5.2/s Avg:? 140 Min:? 107 Max:? 248 Err:? ? 1 (16.67%)
[jmeter] Tidying up ...? ? @ Mon Sep 14 23:14:34 CST 2015 (1442243674232)
[jmeter] ... end of run
[jmeter] Executing test plan: D:\apache-jmeter-2.13\demo\測(cè)試百度.jmx ==> D:\apache-jmeter-2.13\demo\report\jtl\TestReport201509141114.jtl
[jmeter] Creating summariser[jmeter] Created the tree successfully using D:\apache-jmeter-2.13\demo\測(cè)試百度.jmx
[jmeter] Starting the test @ Mon Sep 14 23:14:35 CST 2015 (1442243675376)
[jmeter] Waiting for possible shutdown message on port 4445
[jmeter] summary +? ? ? 1 in? 0.5s =? ? 2.1/s Avg:? 196 Min:? 196 Max:? 196 Err:? ? 0 (0.00%) Active: 1 Started: 1 Finished: 0
[jmeter] summary +? ? ? 5 in? ? 1s =? ? 8.4/s Avg:? 113 Min:? 107 Max:? 133 Err:? ? 0 (0.00%) Active: 0 Started: 1 Finished: 1
[jmeter] summary =? ? ? 6 in? 1.1s =? ? 5.6/s Avg:? 126 Min:? 107 Max:? 196 Err:? ? 0 (0.00%)
[jmeter] Tidying up ...? ? @ Mon Sep 14 23:14:36 CST 2015 (1442243676535)
[jmeter] ... end of run
report:
[xslt] Processing D:\apache-jmeter-2.13\demo\report\jtl\TestReport201509141114.jtl to D:\apache-jmeter-2.13\demo\report\html\TestReport201509141114.html
[xslt] Loading stylesheet D:\apache-jmeter-2.13\extras\jmeter-results-detail-report_21.xsl
[copy] Copying 2 files to D:\apache-jmeter-2.13\demo\report\html
BUILD SUCCESSFUL
Total time: 5 seconds
3挤安、測(cè)試報(bào)告目錄:D:\apache-jmeter-2.13\demo\report\html谚殊,其中有一個(gè)紅色失敗的案例是我故意設(shè)置失敗,以便查看的蛤铜。
四:最后嫩絮,說(shuō)一個(gè)我在使用過(guò)程中碰到一個(gè)問(wèn)題,上面build.xml文件第29行有一句必須要加上:,否則會(huì)報(bào)如下的錯(cuò)誤:
report:
[xslt] Processing D:\Tools\apache-jmeter-2.13\demo\report\jtl\TestReport201509210923.jtl to D:\Tools\apache-jmeter-2.13\demo\report\html\TestReport201509210923.html
[xslt] Loading stylesheet D:\Tools\apache-jmeter-2.13\extras\jmeter-results-detail-report_21.xsl
[xslt] : Error! 前言中不允許有內(nèi)容围肥。
[xslt] : Error! com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: 前言中不允許有內(nèi)容剿干。
[xslt] Failed to process D:\Tools\apache-jmeter-2.13\demo\report\jtl\TestReport201509210923.jtl
因?yàn)椴患由线@一句,生成的.jtl文件是文本文件不是xml文件穆刻,使用xsl去轉(zhuǎn)換.jtl文件時(shí)就會(huì)報(bào)錯(cuò)置尔。
更新補(bǔ)充:
上面生成的報(bào)告有如下兩個(gè)問(wèn)題,解決辦法參見(jiàn)Jmeter自帶報(bào)告優(yōu)化(一):
1氢伟、Date report這里的時(shí)間沒(méi)有正確顯示出來(lái)
2榜轿、Summary里的字段Min Time和Max Time顯示的是NaN,沒(méi)有顯示正確的時(shí)間腐芍。
參考:
1差导、http://rainbow702.iteye.com/blog/2159244
2、http://www.programmerplanet.org/projects/jmeter-ant-task/
作者:Glen.He
出處:http://www.cnblogs.com/puresoul/
本文版權(quán)歸作者和博客園共有猪勇,歡迎轉(zhuǎn)載设褐,但未經(jīng)作者同意必須保留此段聲明,且在文章頁(yè)面明顯位置給出原文連接,否則保留追究法律責(zé)任的權(quán)利助析。
1234567891011121314151617181920212223242526272829303132333435383940414243444546