一、环境准备:
1、JDK:http://www.oracle.com/technetwork/java/javase/downloads/index.html
2、Jmeter:http://jmeter.apache.org/download_jmeter.cgi
3、Ant:http://ant.apache.org/bindownload.cgi
4、Jenkins:http://jenkins-ci.org/
二、Jemter脚本准备:
1、脚本目录:D:\B_TOOLS\apache-jmeter-2.13\demo
2、脚本内容:都是简单的访问百度或google首页
baidu.jmx google.jmx
三、配置Jenkins Job并运行:
1、job配置如下:
2、job运行结果:
1
Started by user anonymous
2 Building in workspace D:\B_TOOLS\jenkins\jobs\TestJenkins\workspace
3 [demo] $ cmd.exe /C \'"ant.bat -file
build3.xml run && exit %%ERRORLEVEL%%"\'
4 Buildfile: build3.xml
5
6 run:
7 [echo] start...
8
9 clean:
10 [mkdir] Created dir: D:\B_TOOLS\jenkins\jobs\TestJenkins\workspace\results\15
11
12 test:
13 [jmeter] Executing test plan: D:\B_TOOLS\apache-jmeter-2.13\demo\baidu.jmx
==> D:\B_TOOLS\jenkins\jobs\TestJenkins\workspace\results\15\TestReport.jtl
14 [jmeter] Creating summariser
15 [jmeter] Created the tree successfully
using D:\B_TOOLS\apache-jmeter-2.13\demo\baidu.jmx
16 [jmeter] Starting the test @ Tue Sep
22 15:50:33 CST 2015 (1442908233010)
17 [jmeter] Waiting for possible shutdown
message on port 4445
18 [jmeter] summary + 1 in 1s = 2.0/s Avg:
254 Min: 254 Max: 254 Err: 0 (0.00%) Active:
1 Started: 1 Finished: 0
19 [jmeter] summary + 5 in 1s = 7.3/s Avg:
131 Min: 96 Max: 196 Err: 0 (0.00%) Active:
0 Started: 1 Finished: 1
20 [jmeter] summary = 6 in 1.2s = 5.0/s
Avg: 151 Min: 96 Max: 254 Err: 0 (0.00%)
21 [jmeter] Tidying up ... @ Tue Sep 22
15:50:34 CST 2015 (1442908234310)
22 [jmeter] ... end of run
23 [jmeter] Executing test plan: D:\B_TOOLS\apache-jmeter-2.13\demo\google.jmx
==> D:\B_TOOLS\jenkins\jobs\TestJenkins\workspace\results\15\TestReport.jtl
24 [jmeter] Creating summariser
25 [jmeter] Created the tree successfully
using D:\B_TOOLS\apache-jmeter-2.13\demo\google.jmx
26 [jmeter] Starting the test @ Tue Sep
22 15:50:35 CST 2015 (1442908235240)
27 [jmeter] Waiting for possible shutdown
message on port 4445
28 [jmeter] summary + 1 in 1s = 1.9/s Avg:
253 Min: 253 Max: 253 Err: 1 (100.00%) Active:
1 Started: 1 Finished: 0
29 [jmeter] summary + 5 in 1.1s = 4.4/s
Avg: 209 Min: 97 Max: 420 Err: 0 (0.00%)
Active: 0 Started: 1 Finished: 1
30 [jmeter] summary = 6 in 2s = 3.6/s Avg:
216 Min: 97 Max: 420 Err: 1 (16.67%)
31 [jmeter] Tidying up ... @ Tue Sep 22
15:50:36 CST 2015 (1442908236992)
32 [jmeter] ... end of run
33
34 report:
35 [xslt] Processing D:\B_TOOLS\jenkins\jobs\TestJenkins\workspace\results\15\TestReport.jtl
to D:\B_TOOLS\jenkins\jobs\TestJenkins\workspace\results\15\TestReport.html
36 [xslt] Loading stylesheet D:\B_TOOLS\apache-jmeter-2.13\extras\jmeter-results-detail-report_21.xsl
37 [copy] Copying 2 files to D:\B_TOOLS\jenkins\jobs\TestJenkins\workspace\results\15
38
39 BUILD SUCCESSFUL
40 Total time: 5 seconds
41 [workspace] $ cmd /c call D:\Users\heman793\AppData\Local\Temp\hudson4765606743104861298.bat
42
43 D:\B_TOOLS\jenkins\jobs\TestJenkins\workspace>echo
D:\B_TOOLS\jenkins\jobs\TestJenkins\workspace
44 D:\B_TOOLS\jenkins\jobs\TestJenkins\workspace
45
46 D:\B_TOOLS\jenkins\jobs\TestJenkins\workspace>echo
15
47 15
48
49 D:\B_TOOLS\jenkins\jobs\TestJenkins\workspace>cd
results
50
51 D:\B_TOOLS\jenkins\jobs\TestJenkins\workspace\results>cd
15
52
53 D:\B_TOOLS\jenkins\jobs\TestJenkins\workspace\results\15>exit
0
54 Finished: SUCCESS |
正文中文字将
3、在job的workspace目录下会生成结果报告:
4、TestReport.html:
更新补充:
上面生成的报告有如下两个问题,解决办法参见Jmeter自带报告优化
1、Date report这里的时间没有正确显示出来
2、Summary里的字段Min Time和Max Time显示的是NaN,没有显示正确的时间。
五、配置发送邮件功能
1、自已写一个发送邮件的功能并打成sendmail.jar包,放在job的workspace目录中
2、jenkins增加构建步骤
a)进入到测试报告的目录
b) 调用sendmail.jar命令发送邮件
说明:
1、由build3.xml的第12、13行可知,报告文件生成目录为:${env.WORKSPACE}/results/${env.BUILD_ID},所以这里我要先cd到具体执行的那个build_id目录下。
2、我们也可以把上面的两行命令写在成一个批处理文件,例如我第1步有个sendmail.bat文件就是的,然后调用时直接写sendmail.bat就好了。
另外,我本文所有脚本都在我本地,其实更好的办法是使用SVN统一管理,这里就不介绍了,感觉的可以自己研究下。
|