Hudson+ant+jmeter自动测试

  • A+
所属分类:技术分享

1.Jmeter下载安装

下载地址:http://jmeter.apache.org/download_jmeter.cgi

解压后,运行apache-jmeter-2.6\bin\jmeter.bat启动jmeter

拷贝ant-jmeter-1.0.9.jar到ant工具的lib下

cp $jmeter_home/extras/ant-jmeter-1.0.9.jar $ant_home/lib/

   
 

2.录制jmeter脚本

详细步骤参照《jmeter脚本录制》

   
 

3.写相应的ant脚本,build.xml如下:

<?xml version="1.0" encoding="UTF-8"?>

   
 

<project name="ant-jmeter-test" default="run" basedir=".">

<tstamp>

<format property="time" pattern="yyyyMMddhhmm" />

</tstamp>

<!-- 需要改成自己本地的 Jmeter 目录-->

<property name="jmeter.home" value="/opt/jmeter/apache-jmeter-2.6" />

<!--<property name="jmeter.result.jtl.dir" value="/opt/jmeter/demo/report/jtl" />

<property name="jmeter.result.html.dir" value="/opt/jmeter/demo/report/html" />-->

<!-- jmeter生成jtl格式的结果报告的路径-->

<property name="jmeter.result.jtl.dir" value="/root/.hudson/jobs/svn-test/workspace/report/jtl" />

<!-- jmeter生成html格式的结果报告的路径-->

<property name="jmeter.result.html.dir" value="/root/.hudson/jobs/svn-test/workspace/report/html" />

<!-- 生成的报告的前缀-->

<property name="ReportName" value="TestReport" />

<!--<property name="jmeter.result.jtlName" value="${jmeter.result.jtl.dir}/${ReportName}${time}.jtl" />

<property name="jmeter.result.htmlName" value="${jmeter.result.html.dir}/${ReportName}${time}.html" />-->

<property name="jmeter.result.jtlName" value="${jmeter.result.jtl.dir}/${ReportName}.jtl" />

<property name="jmeter.result.htmlName" value="${jmeter.result.html.dir}/${ReportName}.html" />

   
 

<!-- 声明jmeter lib下相关jar包-->

<path id="jmeter.path" >

<fileset dir ="${jmeter.home}/lib">

<include name ="**/*.jar"/>

</fileset>

<fileset dir ="${jmeter.home}/extras">

<include name ="**/*.jar"/>

</fileset>

</path>

   
 

<target name="run">

<antcall target="test" />

<antcall target="report" />

</target>

 
 

<target name="test">

<taskdef name="jmeter" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask" classpathref="jmeter.path" />

<jmeter jmeterhome="${jmeter.home}" resultlog="${jmeter.result.jtlName}">

<!-- 声明要运行的脚本。"*.jmx"指包含此目录下的所有jmeter脚本-->

<testplans dir="/opt/jmeter/demo" includes="*.jmx" />

<property name="jmeter.save.saveservice.output_format" value="xml"/>

</jmeter>

</target>

 
 

<path id="xslt.classpath">

<fileset dir="${jmeter.home}/lib" includes="xalan*.jar"/>

<fileset dir="${jmeter.home}/lib" includes="serializer*.jar"/>

</path>

<!--<target name="report">

<xslt in="${jmeter.result.jtlName}"

out="${jmeter.result.htmlName}"

style="${jmeter.home}/extras/jmeter-results-detail-report_21.xsl" />-->

<target name="report">

<tstamp> <format property="report.datestamp" pattern="yyyy/MM/dd HH:mm" /></tstamp>

<xslt

classpathref="xslt.classpath"

force="true"

in="${jmeter.result.jtlName}"

out="${jmeter.result.htmlName}"

style="${jmeter.home}/extras/jmeter-results-detail-report_21.xsl">

<param name="dateReport" expression="${report.datestamp}"/>

</xslt>

<!-- 因为上面生成报告的时候,不会将相关的图片也一起拷贝至目标目录,所以,需要手动拷贝 -->

<copy todir="${jmeter.result.html.dir}">

<fileset dir="${jmeter.home}/extras">

<include name="collapse.png" />

<include name="expand.png" />

</fileset>

</copy>

</target>

</project>

   
 

4:配置hudson执行build.xml中的ant脚本

011818 0228 Hudsonantjm1 - Hudson+ant+jmeter自动测试

    
 

5:配置Hudson,下载Hudson的performance plugin插件,进入到工程配置界面,找到Post-build Actions项,里面多出一个Publish Performance test result report选项。做相应的配置,根据不同的项目要求设置不同的配置,可参照Help.

011818 0228 Hudsonantjm2 - Hudson+ant+jmeter自动测试

   
 

6:运行工程。可得到如下结果:

图示1:

011818 0228 Hudsonantjm3 - Hudson+ant+jmeter自动测试

   
 

图示2:

011818 0228 Hudsonantjm4 - Hudson+ant+jmeter自动测试

点击last Report,如下

图示3:

011818 0228 Hudsonantjm5 - Hudson+ant+jmeter自动测试

头像

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: