1. 程式人生 > >JMeter+Ant-自動發送測試結果報告郵件

JMeter+Ant-自動發送測試結果報告郵件

RoCE eating red 報告 測試結果 自動發送郵件 enc list common

build.xml文件

將這三個jar包(activation.jar、commons-email-1.2.jar、mail.jar)放到ant下的lib下

(我的是:/usr/local/Cellar/ant/1.10.5/libexec/lib)

<?xml version="1.0" encoding="UTF8"?>

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

<property name="jmeterPath" value="/Applications/apache-jmeter-4.0"
/> <property name="mailhost" value="smtp.163.com"/> <property name="username" value="[email protected]"/> <property name="password" value="輸入163郵箱等密碼"/> <property name="mailfrom" value="[email protected]"/> <property name="mail_to" value="[email protected],[email protected]"
/> <property name="mailsubject" value="XX系統接口自動化測試報告"/> <property name="mail_port" value="25"/> <property name="message" value="Hi!請查收下,這是XX接口自動化測試報告,如有任何疑問,請聯系我,謝謝!"/> <tstamp> <format property="time" pattern="yyyyMMddhhmm" /> </tstamp> <
property name="jmeter.home" value="${jmeterPath}" /> <property name="jmeter.result.jtl.dir" value="${jmeterPath}\test\report\jtl" /> <property name="jmeter.result.html.dir" value="${jmeterPath}\test\report\html" /> <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}"> <!--要執行的測試腳本--> <testplans dir="${jmeterPath}\test\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-2.7.2.jar"/> <fileset dir="${jmeter.home}/lib" includes="serializer-2.7.2.jar"/> </path> <!--生成HTML測試報告--> <target name="report"> <echo>生成接口自動測試報告</echo> <xslt classpathref="xslt.classpath" force="true" in="${jmeter.result.jtlName}" out="${jmeter.result.htmlName}" style="${jmeter.home}/extras/jmeter-results-detail-report_21.xsl" /> <!--復制圖片--> <copy todir="${jmeter.result.html.dir}"> <fileset dir="${jmeter.home}/extras"> <include name="collapse.png" /> <include name="expand.png" /> </fileset> </copy> </target> <!--自動發送郵件--> <target name="sendEmail"> <echo>發送自動化測試報告</echo> <mail mailhost="${mailhost}" ssl="ture" user="${username}" password="${password}" mailport="${mail_port}" subject="${mailsubject}" messagemimetype="text/html" tolist="${mail_to}"> <from address="${mailfrom}" /> <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>

執行

(base) localhost:test ligaijiang$ cd /Applications/apache-jmeter-4.0/test
(base) localhost:test ligaijiang$ ant Buildfile: /Applications/apache-jmeter-4.0/test/build.xml run: test: [echo] 執行接口自動化測試 [jmeter] Executing test plan: /Applications/apache-jmeter-4.0/test/script/測試計劃.jmx ==> /Applications/apache-jmeter-4.0/test/report/jtl/TestReport201904270811.jtl [jmeter] WARNING: An illegal reflective access operation has occurred [jmeter] WARNING: Illegal reflective access by com.thoughtworks.xstream.core.util.Fields (file:/Applications/apache-jmeter-4.0/lib/xstream-1.4.10.jar) to field java.util.TreeMap.comparator [jmeter] WARNING: Please consider reporting this to the maintainers of com.thoughtworks.xstream.core.util.Fields [jmeter] WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations [jmeter] WARNING: All illegal access operations will be denied in a future release [jmeter] Creating summariser <summary> [jmeter] Created the tree successfully using /Applications/apache-jmeter-4.0/test/script/測試計劃.jmx [jmeter] Starting the test @ Sat Apr 27 20:11:43 CST 2019 (1556367103226) [jmeter] Waiting for possible Shutdown/StopTestNow/Heapdump message on port 4445 [jmeter] summary + 46 in 00:00:17 = 2.8/s Avg: 354 Min: 72 Max: 2209 Err: 0 (0.00%) Active: 1 Started: 1 Finished: 0 [jmeter] summary + 30 in 00:00:12 = 2.6/s Avg: 387 Min: 64 Max: 4197 Err: 8 (26.67%) Active: 0 Started: 1 Finished: 1 [jmeter] summary = 76 in 00:00:28 = 2.7/s Avg: 367 Min: 64 Max: 4197 Err: 8 (10.53%) [jmeter] Tidying up ... @ Sat Apr 27 20:12:11 CST 2019 (1556367131829) [jmeter] ... end of run report: [echo] 生成接口自動測試報告 [xslt] Processing /Applications/apache-jmeter-4.0/test/report/jtl/TestReport201904270811.jtl to /Applications/apache-jmeter-4.0/test/report/html/TestReport201904270811.html [xslt] Loading stylesheet /Applications/apache-jmeter-4.0/extras/jmeter-results-detail-report_21.xsl sendEmail: [echo] 發送自動化測試報告 [mail] Sending email: XX系統接口自動化測試報告 [mail] Sent email with 3 attachments BUILD SUCCESSFUL Total time: 33 seconds (base) localhost:test ligaijiang$

JMeter+Ant-自動發送測試結果報告郵件