ant构建Jmeter脚本的build文件配置(build.xml)
Posted 51benpao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ant构建Jmeter脚本的build文件配置(build.xml)相关的知识,希望对你有一定的参考价值。
可发送邮件
<?xml version="1.0" encoding="UTF8"?> <project name="ant-jmeter" default="run" basedir="."> <property name="jmeterPath" value="D:apache-jmeter-5.1.1"/> <property name="mail_host" value="smtp.163.com"/> <property name="mail_port" value="465"/> <property name="username" value="XXXXXX@163.com"/> <property name="password" value="1234678"/> <property name="mail_from" value="13XXXXXXXX6@163.com"/> <property name="mail_to" value="l@globw.com,lua@gobw.com"/> <property name="mailsubject" value="Jmeter接口自动化测试报告"/> <property name="message" value="今日接口测试任务已执行完毕,详情请查看附件!!!"/> <tstamp><format property="time" pattern="yyyyMMddHHmm" /></tstamp> <!-- jmeter环境配置 --> <property name="jmeter.home" value="${jmeterPath}"/> <!-- jtl测试结果存放路径 --> <property name="jmeter.result.jtl.dir" value="E:jmeter_script eport"/> <!-- html测试结果存放路径 --> <property name="jmeter.result.html.dir" value="E:jmeter_script eport"/> <property name="htmlReportNameSummary" value="TestReport"/> <property name="jmeter.result.jtlName" value="${jmeter.result.jtl.dir}/${htmlReportNameSummary}${time}.jtl"/> <property name="jmeter.result.htmlName" value="${jmeter.result.html.dir}/${htmlReportNameSummary}${time}.html"/> <target name="run"> <antcall target="test"/> <antcall target="report"/> <antcall target="sendEmail"/> </target> <!-- 执行接口测试 --> <target name="test"> <echo>执行接口自动化测试用例</echo> <taskdef name="jmeter" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask" /> <jmeter jmeterhome="${jmeter.home}" resultlog="${jmeter.result.jtlName}"> <!-- 声明要运行的脚本“*.jmx”指包含此目录下的所有jmeter脚本--> <testplans dir="E:jmeter_script" includes="*.jmx" /> <property name="jmeter.save.saveservice.output_format" value="xml"/> </jmeter> </target> <!-- 解决报告中NAN字段显示问题--> <path id="xslt.classpath"> <fileset dir="${jmeter.home}/lib" includes="xalan*.jar" /> <fileset dir="${jmeter.home}/lib" includes="serializer*.jar" /> </path> <target name="report"> <echo>生成接口自动化测试报告</echo> <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.shanhe.me.xsl" > <param name="titleReport" expression="${mailsubject}${time}"/> <param name="dateReport" expression="${report.datestamp}"/> </xslt> <!-- 因为上面生成报告的时候,不会将相关的图片也一起拷贝至目标目录,所以,需要手动拷贝 --> <copy file="${jmeter.home}/extras/expand.png" tofile="${jmeter.result.html.dir}/expand.png" /> <copy file="${jmeter.home}/extras/collapse.png" tofile="${jmeter.result.html.dir}/collapse.png" /> </target> <target name="sendEmail"> <echo>发送测试报告</echo> <mail mailhost="${mail_host}" ssl="true" user="${username}" password="${password}" mailport="${mail_port}" subject="${mailsubject}" messagemimetype="text/html" tolist="${mail_to}"> <from address="${mail_from}" /> <attachments> <fileset dir="${jmeter.result.html.dir}"> <include name="${htmlReportNameSummary}${time}.html" /> <include name="collapse.png" /> <include name="expand.png" /> </fileset> </attachments> <message> ${message} </message> </mail> </target> </project>
以上是关于ant构建Jmeter脚本的build文件配置(build.xml)的主要内容,如果未能解决你的问题,请参考以下文章
搭建基于Ant+Jmeter+jenkins的自动负载测试框架的若干问题记录及解决
Jenkins+ant_实现Jmeter脚本持续集成测试实例