preparation:
1) install jdk and configure environment variables. Please search for specific steps by yourself
2) install jmeter3.1 and above
3) jmeter installs the mqtt plug-in: Mqtt xmeter - [required version] - jar-with-dependencies.jar , put it in the EXT folder of JMeter installation directory (for example, F:\testPro\apache-jmeter-3.1\lib\ext). Restart JMeter after installation to see the relevant plug-in information, as shown in the figure:
Note: add in github address: https://github.com/emqx/mqtt-jmeter/releases
4) install ant and configure environment variables
5) organize the required jar packages:
- Under the lib folder of ant installation directory (for example, F:\testPro\apache-ant-1.10.5\lib), add the following jar package:
commons-email-1.5.jar, activation.jar, mail.jar, ant-jmeter-1.1.1.jar please download and add by yourself
As shown in the figure:
6) create a new result saving directory testResult (for example, F:\testPro\testResult), and add the following folder under the directory:
html: the. html file to save the test results
jtl: the. jtl file that holds the test results
Scripts: save the jmeter script. jmx file to be tested
7) add the build.xml file to the bin folder of the ant installation directory (for example, F:\testPro\apache-ant-1.10.5\bin). If there is already one, it needs to be modified.
The code of 「 document is as follows, please modify the filling part by yourself:
<?xml version="1.0" encoding="UTF8"?> <project name="ant-jmeter" default="all" basedir="."> <property name="jmeterPath" value="F:\testPro\apache-jmeter-3.1"/> <property name="mail_host" value="smtp.qq.com"/> <property name="mail_port" value="465"/> <property name="username" value="Fill in the sender's email, and note that the email needs to be opened smtp service"/> <property name="password" value="Fill in the smtp Authorization code"/> <property name="mail_from" value="Fill in sender's email"/> <property name="mail_to" value="Fill in to mailbox"/> <property name="mailsubject" value="Mail title"/> <property name="message" value="test"/> <tstamp><format property="time" pattern="yyyyMMddhhmm" /></tstamp> <!-- jmeter Environmental configuration --> <property name="jmeter.home" value="${jmeterPath}"/> <!-- jtl Storage path of test results --> <property name="jmeter.result.jtl.dir" value="Fill.jtl Document storage directory"/> <!-- html Storage path of test results --> <property name="jmeter.result.html.dir" value="Fill.html Document storage directory"/> <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="all"> <antcall target="test"/> <antcall target="report"/> <antcall target="sendEmail"/> </target> <!-- Perform interface tests --> <target name="test"> <echo>Execute automated test cases</echo> <taskdef name="jmeter" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask" /> <jmeter jmeterhome="${jmeter.home}" resultlog="${jmeter.result.jtlName}"> <testplans dir="Fill.jmx Document storage address" includes="Fill.jmx file name"/> <property name="jmeter.save.saveservice.output_format" value="xml" /> </jmeter> </target> <!-- Resolution Report NAN Field display problems--> <path id="xslt.classpath"> <fileset dir="${jmeter.home}/lib" includes="xalan-2.7.2.jar" /> <fileset dir="${jmeter.home}/lib" includes="serializer-2.7.2.jar" /> </path> <target name="report"> <echo>Generate automated test reports</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-detail-report_21.xsl" > <param name="titleReport" expression="${mailsubject}${time}"/> <param name="dateReport" expression="${report.datestamp}"/> </xslt> <!-- Because when the report is generated above, the related images will not be copied to the target directory together, so you need to copy them manually --> <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>Send test report</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>
Implementation:
1) put jmeter Script. jmx in Script directory
2) in the bin directory of ant (for example, F:\testPro\apache-ant-1.10.5\bin), open cmd or other command-line tools, and directly enter ant to run
3) wait for operation to complete production test report