接口测试很难吗?学会JMeter+Ant接口自动化搭建及实践( 二 )


4、在本地任意创建目录testcases(如:D:testcases) , 并在其目录下创建report文件夹和build.xml文件 , 复制以下内容到build.xml文件中:
<?xml version="1.0" encoding="UTF-8"?>
<project name="ant-jmeter-test" default="all" basedir=".">
<tstamp>
<format property="time" pattern="yyyyMMddhhmm" />
</tstamp>
<!-- 需要改成自己本地的 Jmeter 目录 -->
<property name="jmeter.home" value=https://www.isolves.com/it/cxkf/bk/2020-09-09/"D:Apachejmeter" />
<property name="report.title" value=https://www.isolves.com/it/cxkf/bk/2020-09-09/"测试报告" />
<!-- jmeter生成jtl格式的结果报告的路径 -->
<property name="jmeter.result.jtl.dir" value=https://www.isolves.com/it/cxkf/bk/2020-09-09/"D:testcasesreport" />
<!-- jmeter生成html格式的结果报告的路径 -->
<property name="jmeter.result.html.dir" value=https://www.isolves.com/it/cxkf/bk/2020-09-09/"D:testcasesreport" />
<!-- zip文件路径 -->
<property name="zip.dir" value=https://www.isolves.com/it/cxkf/bk/2020-09-09/"D:testcases" />
<!-- 生成的报告的前缀 -->
<property name="ReportName" value=https://www.isolves.com/it/cxkf/bk/2020-09-09/"testcases" />
<!-- 报告名称 -->
<property name="jmeter.result.jtlName" value=https://www.isolves.com/it/cxkf/bk/2020-09-09/"${jmeter.result.jtl.dir}/${ReportName}${time}.jtl" />
<property name="jmeter.result.htmlName" value=https://www.isolves.com/it/cxkf/bk/2020-09-09/"${jmeter.result.html.dir}/${ReportName}${time}.html" />
<property name="zipname" value=https://www.isolves.com/it/cxkf/bk/2020-09-09/"${zip.dir}/${ReportName}${time}.zip" />
<!-- 邮件配置信息 -->
<property name="mail_host" value=https://www.isolves.com/it/cxkf/bk/2020-09-09/"smtp.163.com" />
<property name="mail_port" value=https://www.isolves.com/it/cxkf/bk/2020-09-09/"465" />
<property name="username" value=https://www.isolves.com/it/cxkf/bk/2020-09-09/"testcases@163.com" />
<property name="password" value=https://www.isolves.com/it/cxkf/bk/2020-09-09/"123456789" />
<property name="mail_from" value=https://www.isolves.com/it/cxkf/bk/2020-09-09/"dtestcases@163.com" />
<property name="mail_to" value=https://www.isolves.com/it/cxkf/bk/2020-09-09/"testcases@163.com,testcases2@163.com" />
<property name="mailsubject" value=https://www.isolves.com/it/cxkf/bk/2020-09-09/"测试报告" />
<!-- 输出生成的报告名称和存放路径 -->
<echo message="${jmeter.result.jtlName}" />
<echo message="${jmeter.result.htmlName}" />
<echo message="${jmeter.result.html.dir}" />
<echo message="${zip.dir}" />
<echo message="${zipname}" />
<!-- 加载jar包 , 解决时间显示问题 -->
<path id="xslt.classpath">
<fileset dir="${jmeter.home}/lib" includes="xalan*.jar" />
<fileset dir="${jmeter.home}/lib" includes="serializer*.jar" />
</path>
<target name="all">
<antcall target="test" />
<antcall target="report" />
<antcall target="summary-report" />
<antcall target="zip" />
<!-- 打包zip -->
<antcall target="sendEmail" />
<!-- 发送邮件 -->
</target>
<target name="test">
<taskdef name="jmeter" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask" />
<jmeter jmeterhome="${jmeter.home}" resultlog="${jmeter.result.jtlName}">
<!-- 声明要运行的脚本"*.jmx"指包含此目录下的所有jmeter脚本 -->
<!-- 如果只想执行部分脚本 , 可以写多条testplans 将需要执行的jmx写在includes中 -->
<testplans dir="D:testcases" includes="*.jmx" />
<property name="jmeter.save.saveservice.output_format" value=https://www.isolves.com/it/cxkf/bk/2020-09-09/"xml" />
<!-- 这里就是jmeter.properties修改的部分 -->
</jmeter>
</target>
<target name="report">
<tstamp>
<format property="report.datestamp" pattern="yyyy/MM/dd HH:mm" />
</tstamp>
<xslt classpathref=https://www.isolves.com/it/cxkf/bk/2020-09-09/"xslt.classpath" force="true" in="${jmeter.result.jtlName}" out="${jmeter.result.html.dir}/summary-report.html" style="${jmeter.home}/extras/jmeter.results.shanhe.me.xsl">


推荐阅读