jmeter-ant-jekins

1,安装ant

解压ant之后,在环境变量中配置ant,新建ANT_HOME,见截图

 

然后在path环境变量中加入%ANT_HOME%\bin,配置完成后,打开cmd命令提示符,输入ant -v ,出现如下截图,说明ant环境配置OK,见截图

2、修改jmeter配置文件jmeter.properties,把jmeter.save.saveservice.output_format=csv修改为jmeter.save.saveservice.output_format=xml,并不要注释,见截图

3,在jmeter的extras目录下,把ant-jmeter-1.1.1.jar文件复制到ant的lib目录下,见截图

4,新建build.xml 放入到ant 目录下

 build.xml内容如下:

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <project name="ant-jmeter-test" default="run" basedir=".">
 3 
 4  <!-- (1)需要改成自己本地的 Jmeter 目录-->
 5 <property name="jmeter.home" value="E:\software\apache-jmeter-3.2\apache-jmeter-3.2"/>
 6 <property name="report.title" value="report"/>
 7 <!-- (2)jmeter生成jtl格式的结果报告的路径-->
 8 <property name="jmeter.result.jtl.dir" value="E:\software\apache-jmeter-3.2\apache-jmeter-3.2\demo\resultLog\jtl"/>
 9 <!-- (3)jmeter生成html格式的结果报告的路径-->
10 <property name="jmeter.result.html.dir" value="E:\software\apache-jmeter-3.2\apache-jmeter-3.2\demo\resultLog\html"/>
11 <!-- 生成的报告的前缀 -->
12 <property name="ReportName" value="TestReport"/>
13 <property name="jmeter.result.jtlName" value="${jmeter.result.jtl.dir}/${ReportName}.jtl"/>
14 <property name="jmeter.result.htmlName" value="${jmeter.result.html.dir}/${ReportName}.html"/>
15 
16 <target name="run"> 
17   <antcall target="test"/>  
18   <antcall target="report"/> 
19   <!--antcall  target="mail"/-->    
20 </target>
21 <target name="test"> 
22   <taskdef name="jmeter" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask"/>  
23   <jmeter jmeterhome="${jmeter.home}" resultlog="${jmeter.result.jtlName}"> 
24   <!-- (4)jmeter脚本的存放的路径-->
25     <testplans dir="E:\software\apache-jmeter-3.2\apache-jmeter-3.2\demo" includes="*.jmx"/>  
26     <property name="jmeter.save.saveservice.output_format" value="xml"/> 
27   </jmeter> 
28 </target>
29 <path id="xslt.classpath"> 
30   <fileset dir="${jmeter.home}/lib" includes="xalan*.jar"/>  
31   <fileset dir="${jmeter.home}/lib" includes="serializer*.jar"/> 
32 </path>
33 <target name="report"> 
34   <tstamp> 
35     <format property="report.datestamp" pattern="yyyy/MM/dd HH:mm"/>
36   </tstamp>  
37   <xslt 
38   classpathref="xslt.classpath" 
39   force="true" 
40   in="${jmeter.result.jtlName}"
41   out="${jmeter.result.htmlName}"
42   
43   style="${jmeter.home}/extras/jmeter-results-detail-report_21.xsl"> 
44     <param name="dateReport" expression="${report.datestamp}"/> 
45   </xslt>  
46 
47   <copy todir="${jmeter.result.html.dir}"> 
48     <fileset dir="${jmeter.home}/extras"> 
49       <include name="collapse.png"/>  
50       <include name="expand.png"/> 
51     </fileset> 
52   </copy> 
53 </target>
54  <path id="lib_classpath">
55         <fileset dir="${basedir}/">
56             <include name="mail*.jar" />
57             <include name="activation*.jar" />
58             <include name="commons-email*.jar" />
59             <include name="ant-contrib*.jar" />
60         </fileset>
61  </path>
62 </project>

5,在jmeter安装目录创建demo文件夹用来存放jmeter脚本和ant运行结果

 

 

 

 6,打开dos窗口,cd到buil.xml路径下,之后执行ant或者 ant run

 

 

 7,JMeter Ant Task 生成的*.jtl打开之后request和response data是空的,怎样让其不是空的呢?修改JMeter.properties,将jmeter.save.saveservice多处的false改成true,保存之后重启JMeter生效

# legitimate values: none, first, all
#jmeter.save.saveservice.assertion_results=none
jmeter.save.saveservice.assertion_results=all
#
#jmeter.save.saveservice.data_type=true
#jmeter.save.saveservice.label=true
#jmeter.save.saveservice.response_code=true
# response_data is not currently supported for CSV output
#jmeter.save.saveservice.response_data=false
jmeter.save.saveservice.response_data=true
# Save ResponseData for failed samples
#jmeter.save.saveservice.response_data.on_error=false
jmeter.save.saveservice.response_data.on_error=true
#jmeter.save.saveservice.response_message=true
jmeter.save.saveservice.response_message=true
#jmeter.save.saveservice.successful=true
#jmeter.save.saveservice.thread_name=true
#jmeter.save.saveservice.time=true
#jmeter.save.saveservice.subresults=true
#jmeter.save.saveservice.assertions=true
#jmeter.save.saveservice.latency=true
#jmeter.save.saveservice.samplerData=false
jmeter.save.saveservice.samplerData=true
#jmeter.save.saveservice.responseHeaders=false
jmeter.save.saveservice.responseHeaders=true
#jmeter.save.saveservice.requestHeaders=false
jmeter.save.saveservice.requestHeaders=true
#jmeter.save.saveservice.encoding=false
#jmeter.save.saveservice.bytes=true
#jmeter.save.saveservice.url=false
jmeter.save.saveservice.url=true
#jmeter.save.saveservice.filename=false
jmeter.save.saveservice.filename=true
#jmeter.save.saveservice.hostname=false
jmeter.save.saveservice.hostname=true
#jmeter.save.saveservice.thread_counts=false
#jmeter.save.saveservice.sample_count=false
#jmeter.save.saveservice.idle_time=false

8,进入jekins 创建一个项目

 

选择第一个自由风格,然后点击OK按钮

 

 然后配置ant,增加build路径

 

 

 

 

 

 

点击保存之后,我们继续配置测试报告

 

我们需要下载一个插件Public HTML reports

 

系统管理----》管理插件----》可选插件   输入Public HTML reports 进行查询并进行安装

或者通过离线安装包htmlpublisher.hpi安装

接下来继续配置报告

点击增加构建后操作步骤  并点击Public HTML reports

 

 

并点击保存按钮  好了  现在我们报告也配置好了

 

我们现在jenkins构建下吧

  

我们在jenkins下面看下报告吧

posted on 2019-12-27 15:48  鶸。  阅读(261)  评论(2编辑  收藏  举报