1. 程式人生 > >ant+jmeter+jenkins 發送測試報告郵件

ant+jmeter+jenkins 發送測試報告郵件

ret alt http請求 maximum 一起 fall 找到 acc trace

二、部署配置

2.1 jmeter

2.1.1 jar包二次開發:

將jmeter目錄D:\apache-jmeter-5.0\extras中的ant-jmeter-1.1.1.jar包進行反編譯。添加2個測試類 MailTask和JavaMail。具體代碼參考文件中的java文件。然後進行編譯生成新的jar包ant-jmeter-1.1.2-SNAPSHOT.jar。

2.1.2 添加build文件和測試文件

在jmeter目錄D:\apache-jmeter-5.0\test下新增文件build.xml。

將需要測試的.jmx文件復制到目錄D:\apache-jmeter-5.0\test。(與build.xml文件同目錄)

2.1.3新增測試報告存儲目錄

在D:\apache-jmeter-5.0\test目錄下新增文件目錄report/jtl和report/html。這2個目錄會存儲測試執行後的報告文件。

2.2 ant

2.2.1 添加依賴jar包

在目錄D:\apache-ant-1.10.5\lib下添加依賴jar包。javax.mail-1.5.5.jar,activation-1.1.1.jar,mail-2017.10.2.jar,ant-jmeter-1.1.2-SNAPSHOT.jar。

Jar包可以在二次開發時下載找到。

2.3 jenkins

2.3.1 下載war包部署至tomcat

下載jenkins包,直接在tomcat部署。點擊start.sh 執行。詳情請百度。

JavaMail 
package org.programmerplanet.ant.taskdefs.jmeter;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;

import javax.activation.DataHandler;
import javax.activation.FileDataSource; import javax.mail.Address; import javax.mail.Authenticator; import javax.mail.BodyPart; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.Multipart; import javax.mail.PasswordAuthentication; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeBodyPart; import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMultipart; import javax.mail.internet.MimeUtility; public class JavaMail { static File mailAttachmentFile; static public void sendMail(int all, int successnum, int failnum, String htmlstring, String mailSubject, String mailAttachment, String mailAddress, String mailAddressCC, String mailHost, String mailProtocol, String mailHostPort, String mailAddressFrom, String mailAddressFromPwd,String jmeterProjectName,String testCaseStartTime) throws MessagingException, UnsupportedEncodingException { String s; String passStatus;//判定測試狀態,測試通過,還是測試失敗 String failnumFormat = "";//處理失敗數為0時,不要紅色顯示,失敗數大於0時才顯示 DecimalFormat df = new DecimalFormat("0.00"); String testCaseEndTime = ""; SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); if (all == 0) { s = "0"; passStatus="無用例被執行"; } else { s = df.format((float) successnum / (float) all * 100); if(failnum>0){ passStatus = "<font color=red>Fail</font>"; failnumFormat = "<font color=red>" + failnum + "</font>"; }else { passStatus = "<font color=green>Pass</font>"; failnumFormat = failnum + ""; } //用例結束時間標註為發郵件時間 testCaseEndTime = simpleDateFormat.format(new Date()); } Properties props = new Properties(); // 開啟debug調試 // props.setProperty("mail.debug", "true"); // 發送服務器需要身份驗證 props.setProperty("mail.smtp.auth", "flase"); // 設置郵件服務器主機名(ip或者域名) props.setProperty("mail.smtp.host", mailHost); // 發送郵件協議名稱 props.setProperty("mail.transport.protocol", mailProtocol); // 發送郵件協議端口 props.setProperty("mail.smtp.port", mailHostPort); //props.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); // props.setProperty("mail.smtp.ssl.enable", "true");//保證使用ssl時可以發送成功 //props.setProperty("mail.smtp.socketFactory.port", "465"); //props.setProperty("mail.smtp.socketFactory.fallback", "false"); // 設置環境信息 Session session = Session.getDefaultInstance(props, new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(mailAddressFrom, mailAddressFromPwd); } }); // 創建郵件對象 Message msg = new MimeMessage(session); // 設置發件人 msg.setFrom(new InternetAddress(mailAddressFrom)); // 設置收件人 @SuppressWarnings("static-access") Address[] addresses = new InternetAddress().parse(mailAddress); @SuppressWarnings("static-access") Address[] addressesCC = new InternetAddress().parse(mailAddressCC); msg.setRecipients(Message.RecipientType.TO, addresses);// 直送對象 msg.setRecipients(Message.RecipientType.CC, addressesCC);// 抄送對象 // 設置主題 if (mailSubject != null) { if(passStatus.equals("<font color=red>Fail</font>")){ msg.setSubject("【自動化結果通知--Failure】:" + jmeterProjectName); }else if(passStatus.equals("<font color=green>Pass</font>")){ msg.setSubject("【自動化結果通知--Successful】:" + jmeterProjectName); } } else { msg.setSubject("接口測試報告"); } // 設置郵件內容 BodyPart bp = new MimeBodyPart(); Multipart mp = new MimeMultipart(); bp.setContent( "<!DOCTYPE html>" + "<html><head><META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">" + "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no\" />" + "<title>JMeter Test Results</title>" + "<style type=\"text/css\">" + "body {background: #ffffff;margin: 0 auto;padding: 0;text-align: left;font-size: 12px;font-family: \"微軟雅黑\", \"宋體\";}" + "table {font-size: 12px;font-family: \"微軟雅黑\", \"宋體\";}" + "td {line-height: 20px;}" + "</style></head><body>" + "<table width=\"800\" border=\"0\" cellspacing=\"0\" align=\"center\" cellpadding=\"0\" style=\"border: #ccc 1px solid;\">" + "<tbody><tr><td>" + "<table width=\"800\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"#fbfbfb\" style=\"border-bottom: #eeeeee 1px solid;border-top: #cc0000 1px solid;\">" + "<tbody><tr><td width=\"100\"><img src=\"http://www.uml.org.cn/jmshj/images/20131211411.jpg\" alt=\"測試結果\" width=\"100\" height=\"40\"></td>" + "<td width=\"264\" align=\"right\" style=\"font-size: 12px; font-weight: bold; color: #999999;padding-top: 5px;\"><font color=\"#136ec2\" style=\"font-size:large\">Hi All <br></font>此信為系統郵件,請不要直接回復。</td></tr></tbody></table>" + "<table width=\"750\" border=\"0\" align=\"center\" cellspacing=\"0\" cellpadding=\"0\" style=\"margin: 28px 28px 10px 28px;\">" + "<tbody><tr><td style=\"font-size: 16px; color: #666666; padding-bottom: 6px;\" align=\"center\"><h2>接口測試報告</h2></td></tr></tbody></table>" + "<table width=\"750\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\"><tbody><tr><td>" + "<table width=\"750\" border=\"0\" align=\"center\" class=\"table_c\" style=\"border-collapse:collapse;\"><tbody><tr>" + "<th width=\"100\" height=\"28\" align=\"center\" bgcolor=\"#FFFFFF\" style=\"border:1px solid #ccc;\">測試項目</th>" + "<th width=\"70\" height=\"28\" align=\"center\" bgcolor=\"#FFFFFF\" style=\"border:1px solid #ccc;\">測試狀態</th>" + "<th width=\"70\" height=\"28\" align=\"center\" bgcolor=\"#FFFFFF\" style=\"border:1px solid #ccc;\">用例總數</th>" + "<th width=\"70\" height=\"28\" align=\"center\" bgcolor=\"#FFFFFF\" style=\"border:1px solid #ccc;\">成功</th>" + "<th width=\"70\" height=\"28\" align=\"center\" bgcolor=\"#FFFFFF\" style=\"border:1px solid #ccc;\">失敗</th>" + "<th width=\"70\" height=\"28\" align=\"center\" bgcolor=\"#FFFFFF\" style=\"border:1px solid #ccc;\">通過率</th>" + "<th width=\"100\" height=\"28\" align=\"center\" bgcolor=\"#FFFFFF\" style=\"border:1px solid #ccc;\">開始時間</th>" + "<th width=\"100\" height=\"28\" align=\"center\" bgcolor=\"#FFFFFF\" style=\"border:1px solid #ccc;\">結束時間</th></tr>" + "<tr><td height=\"28\" bgcolor=\"#FFFFFF\" align=\"center\" style=\"border:1px solid #ccc;\">" + jmeterProjectName + "</td>" + "<td height=\"28\" bgcolor=\"#FFFFFF\" align=\"center\" style=\"border:1px solid #ccc;\">" + passStatus + "</td>" + "<td height=\"28\" bgcolor=\"#FFFFFF\" align=\"center\" style=\"border:1px solid #ccc;\">" + all + "</td>" + "<td height=\"28\" bgcolor=\"#FFFFFF\" align=\"center\" style=\"border:1px solid #ccc;\">" + successnum + "</td>" + "<td height=\"28\" bgcolor=\"#FFFFFF\" align=\"center\" style=\"border:1px solid #ccc;\">" + failnumFormat + "</td>" + "<td height=\"28\" bgcolor=\"#FFFFFF\" align=\"center\" style=\"border:1px solid #ccc;\">" + s + "%</td>" + "<td height=\"28\" bgcolor=\"#FFFFFF\" align=\"center\" style=\"border:1px solid #ccc;\">" + testCaseStartTime + "</td>" + "<td height=\"28\" bgcolor=\"#FFFFFF\" align=\"center\" style=\"border:1px solid #ccc;\">" + testCaseEndTime + "</td></tr></tbody></table></td></tr></tbody></table></td></tr>" + "<tr><td style=\"font-size: 12px; line-height: 20px; color: #999999; padding-top:15px; padding-left:25px \">備註:測試報告詳細內容見郵件附件。</td></tr><tr><td>" + "<table width=\"750\" border=\"0\" align=\"center\" cellspacing=\"0\" cellpadding=\"0\" style=\"margin: 28px 28px 10px 28px;\">" + "<tbody><tr><td style=\"font-size: 12px; color: #666666; padding-bottom: 6px;\"><strong style=\"color:red\">失敗用例:</strong></td></tr></tbody></table>" + "<table width=\"750\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\"><tbody>" + htmlstring //失敗的用例,如無用例失敗,則顯示無 + "</tbody></table>" + "<table width=\"750\" border=\"0\" align=\"center\" cellspacing=\"0\" cellpadding=\"0\" style=\"margin: 28px 28px 10px 28px;\">" + "<tbody><tr><td style=\"font-size: 12px; line-height: 20px; color: #999999; padding-top: 6px;\">如果您對本次郵件有任何疑問,請聯系測試小組人員,感謝您的查閱!</td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></body></html>", "text/html;charset=utf-8"); mp.addBodyPart(bp); // 附件為空時不發附件 // mailAttachmentFile = new // File(System.getProperty("user.dir")+mailAttachment); mailAttachmentFile = new File(mailAttachment); if (mailAttachmentFile.exists()) { System.out.println("把mailAttachment報告文件作為附件發送"); bp = new MimeBodyPart(); // FileDataSource fileds = new // FileDataSource(System.getProperty("user.dir")+mailAttachment); FileDataSource fileds = new FileDataSource(mailAttachment); bp.setDataHandler(new DataHandler(fileds)); bp.setFileName(MimeUtility.encodeText(fileds.getName(), "UTF-8", "B")); mp.addBodyPart(bp); } else { System.out.println("mailAttachment文件不存在,郵件添加附件失敗,請檢查!"); } msg.setContent(mp); msg.saveChanges(); Transport transport = session.getTransport(); // 連接郵件服務器 transport.connect(); // 發送郵件 Transport.send(msg); // 關閉連接 transport.close(); } }
build文件
<?xml version="1.0" encoding="GB2312"?>
 
<project name="ant-jmeter-test" default="run" basedir=".">
    <!--自動觸發測試成功456-->
    <tstamp>
        <format property="time" pattern="yyyyMMddHHmmss" />
    </tstamp>
    <property environment="env"/>
    <!-- 需要改成自己本地的 Jmeter 目錄-->  
    <property name="jmeter.home" value="D:\apache-jmeter-5.0" />
    <!-- jmeter生成jtl格式的結果報告的路徑--> 
    <!--<property name="jmeter.result.jtl.dir" value="D:\apache-jmeter-3.1\demo\report\jtl" />-->
    <!-- jmeter生成html格式的結果報告的路徑-->
    <!--<property name="jmeter.result.html.dir" value="D:\apache-jmeter-3.1\demo\report\html" />-->
    <!-- jmeter生成jtl、html格式的結果報告的路徑--> 
    <property name="jmeter.result.jtl.dir" value="D:\apache-jmeter-5.0\test\report\jtl" />
    <property name="jmeter.result.html.dir" value="D:\apache-jmeter-5.0\test\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" />
    <!-- GIT拉取到本地目錄路徑 
    <property name="githome" value="${env.WORKSPACE}/接口自動化測試/接口測試" />-->
    
    <target name="run">
        <echo message="start..."/>
        <!--<antcall target="clean" />-->
        <antcall target="test" />
        <antcall target="report" />
        <antcall target="mail" />
    </target>
    <!--
    <target name="clean">
        <mkdir dir="${env.WORKSPACE}/results/${env.BUILD_ID}" />
    </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 dir="D:\apache-jmeter-5.0\test" 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">
        <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_30.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>
    
    <target name="mail">
        <taskdef name="javamail" classname="org.programmerplanet.ant.taskdefs.jmeter.MailTask"/>
        <javamail 
            resultLog="${jmeter.result.jtlName}" 
            mailAddressFrom="" 
            mailAddressFromPwd="" 
            jmeterProjectName="XXX項目接口測試" 
            mailAddress="[email protected]"
            mailAddressCC="[email protected]"
            mailHost=""
            mailProtocol="smtp"
            mailHostPort=""
            mailSubject="${ReportName}${time}"
            mailAttachment="${jmeter.result.htmlName}">
        </javamail>
        <!--
        mailAddressFrom:發件人郵箱
        mailAddressFromPwd:發件人郵箱密碼
        jmeterProjectName:本腳本主題是什麽
        mailAddress:收件人郵箱,多個郵箱間逗號隔開
        mailAddressCC:抄送件人郵箱,多個郵箱間逗號隔開
        mailHost:發件人郵箱服務器地址
        mailProtocol:郵箱服務器協議
        mailHostPort:郵箱服務器端口
        resultLog:jtl文件,不需要修改
        mailSubject:html文件,不需要修改
        mailAttachment:附件,不需要修改
        -->
        
        <echo>發送報告郵件 at ${time}</echo>
    </target>
 
</project>

MailTask 類
package org.programmerplanet.ant.taskdefs.jmeter;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

import javax.mail.MessagingException;

import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;

public class MailTask extends Task {
    private String mailAddress = null;// 主送郵件對象地址
    private String mailAddressCC = null;// 抄送郵件對象地址
    private String mailSubject = null;// 郵件主題
    private String mailAttachment = null;// 郵件附件
    private String mailHost = null;// 郵件服務器
    private String mailProtocol = null;// 發送郵件協議
    private String mailHostPort = null;// 發送郵件協議的端口
    private String mailAddressFrom = null;// 發件人
    private String mailAddressFromPwd = null;// 發件人密碼,是授權碼
    private String jmeterProjectName = null;// jmeter腳本名字

    private String resultLog = null;
    File resultLogFile;
    File htmlFile;

    // jtl文件
    public void setResultLog(String resultLog) {
        this.resultLog = resultLog;
    }

    public String getResultLog() {
        return resultLog;
    }

    // 郵件主題
    public void setMailSubject(String mailSubject) {
        this.mailSubject = mailSubject;
    }

    public String getMailSubject() {
        return mailSubject;
    }

    // 附件 html報告文件
    public void setMailAttachment(String mailAttachment) {
        this.mailAttachment = mailAttachment;
    }

    public String getMailAttachment() {
        return mailAttachment;
    }

    // 收件地址,多個逗號(英文)隔開
    public void setMailAddress(String mailAddress) {
        this.mailAddress = mailAddress;
    }

    public String getMailAddress() {
        return mailAddress;
    }

    // 抄送郵件地址,多個逗號(英文)隔開
    public void setMailAddressCC(String mailAddressCC) {
        this.mailAddressCC = mailAddressCC;
    }

    public String getMailAddressCC() {
        return mailAddressCC;
    }

    public void setMailHost(String mailHost) {
        this.mailHost = mailHost;
    }

    public String getMailHost() {
        return mailHost;
    }

    public void setMailProtocol(String mailProtocol) {
        this.mailProtocol = mailProtocol;
    }

    public String getMailProtocol() {
        return mailProtocol;
    }

    public void setMailAddressFrom(String mailAddressFrom) {
        this.mailAddressFrom = mailAddressFrom;
    }

    public String getMailAddressFrom() {
        return mailAddressFrom;
    }

    public void setMailAddressFromPwd(String mailAddressFromPwd) {
        this.mailAddressFromPwd = mailAddressFromPwd;
    }

    public String getMailAddressFromPwd() {
        return mailAddressFromPwd;
    }

    public void setMailHostPort(String mailHostPort) {
        this.mailHostPort = mailHostPort;
    }

    public String getMailHostPort() {
        return mailHostPort;
    }

    public void setJmeterProjectName(String jmeterProjectName) {
        this.jmeterProjectName = jmeterProjectName;
    }

    public String getJmeterProjectName() {
        return jmeterProjectName;
    }

    /**
     * @see org.apache.tools.ant.Task#execute() task執行的入口
     */
    public void execute() throws BuildException {
        System.out.println("開始執行發送郵件task");
        // resultLogFile = new File(System.getProperty("user.dir") + resultLog);
        resultLogFile = new File(resultLog);
        if (mailAddress != null && resultLogFile.exists()) {

            System.out.println("開始解析resultLog");
            try {
                analyseResultLog();
            } catch (MessagingException e) {
                e.printStackTrace();
            }
        } else {
            System.out.println("resultLog不存在,請檢查!");
        }
    }

    /**
     * 計算統計數據
     *
     * @throws MessagingException
     */
    private void analyseResultLog() throws BuildException, MessagingException {

        /*
         * String htmlString = "<tr valign=\"top\">" +
         * "<th width=\"50%\">接口</th>" + "<th>執行結果</th>" + "<th>執行時間</th>" +
         * "</tr>";
         */
        String htmlString = "<tr><th width=\"250\" height=\"28\" align=\"center\" bgcolor=\"#FFFFFF\" style=\"border:1px solid #ccc;\">接口</th>"
                + "<th width=\"65\" height=\"28\" align=\"center\" bgcolor=\"#FFFFFF\" style=\"border:1px solid #ccc;\">執行結果</th>"
                + "<th width=\"65\" height=\"28\" align=\"center\" bgcolor=\"#FFFFFF\" style=\"border:1px solid #ccc;\">執行時間</th></tr>";
        String time;
        String name;
        int count = 0;// 總用例數量
        String color;
        String color1 = "#FFFFFF";// 白色
        String color2 = "#FF0000";// 紅色
        int successnum = 0;// 成功用例數量
        int failnum = 0;// 失敗用例數量
        String testCaseStartTime = "";
        SimpleDateFormat simpleDateFormat = null;
        try {
            // FileInputStream fis = new
            // FileInputStream(System.getProperty("user.dir") + resultLog);
            FileInputStream fis = new FileInputStream(resultLog);
            InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
            BufferedReader br = new BufferedReader(isr);
            String line = null;
            while ((line = br.readLine()) != null) {
                if (line.indexOf("<httpSample ") != -1) {
                    count = count + 1;// 統計用例個數
                    simpleDateFormat = new SimpleDateFormat(
                            "yyyy-MM-dd HH:mm:ss");
                    // 獲取用例開始時間
                    if(count==1){
                        String startTimeMilTime = line.split("\"")[9];
                        testCaseStartTime = simpleDateFormat.format(Long
                                .parseLong(startTimeMilTime));
                    }
                    if (line.indexOf(" s=\"true\"") != -1) {
                        successnum = successnum + 1;
                        color = color1;
                        time = line.split("\"")[1];
                        name = line.split("\"")[13];
                        //不顯示成功的用例
                        /*htmlString = htmlString
                                + "<tr><td height=\"28\" bgcolor=\"#FFFFFF\" align=\"center\" style=\"border:1px solid #ccc;\">"
                                + name
                                + "</td>"
                                + "<td height=\"28\" bgcolor=\""
                                + color
                                + "\" align=\"center\" style=\"border:1px solid #ccc;\">成功</td>"
                                + "<td height=\"28\" bgcolor=\"#FFFFFF\" align=\"center\" style=\"border:1px solid #ccc;\">"
                                + time + "ms</td></tr>";*/
                    } else {
                        failnum = failnum + 1;
                        color = color2;
                        time = line.split("\"")[1];
                        name = line.split("\"")[13];
                        htmlString = htmlString
                                + "<tr><td height=\"28\" bgcolor=\"#FFFFFF\" align=\"center\" style=\"border:1px solid #ccc;\">"
                                + name
                                + "</td>"
                                + "<td height=\"28\" bgcolor=\"#FFFFFF\" align=\"center\" style=\"border:1px solid #ccc;\"><font color="
                                + color
                                + ">失敗</font></td>"
                                + "<td height=\"28\" bgcolor=\"#FFFFFF\" align=\"center\" style=\"border:1px solid #ccc;\">"
                                + time + "ms</td></tr>";
                    }
                }
            }

            // 無失敗用例的時候,直接顯示無即可
            if (failnum <= 0) {
                htmlString = "<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;~~~太棒啦,沒有失敗的用例哦&nbsp;&nbsp;^_^</td></tr>";
            }
            if (successnum + failnum > 0) {
                // 有http請求才發郵件
                JavaMail.sendMail(successnum + failnum, successnum, failnum,
                        htmlString, mailSubject, mailAttachment, mailAddress,
                        mailAddressCC, mailHost, mailProtocol, mailHostPort,
                        mailAddressFrom, mailAddressFromPwd, jmeterProjectName,
                        testCaseStartTime);
                System.out.println("郵件發送成功");

            }
            br.close();
            isr.close();
            fis.close();
        } catch (IOException e) {
            throw new BuildException("Could not read jmeter resultLog: "
                    + e.getMessage());
        }
    }

}

ant+jmeter+jenkins 發送測試報告郵件