寫(xiě)在最前面:
jmeter:測(cè)試接口的工具,支持java語(yǔ)言拿撩;
ant:Apache Ant是一個(gè)Java庫(kù)和命令行工具新思,其任務(wù)是將構(gòu)建文件中描述的進(jìn)程作為相互依賴的目標(biāo)和擴(kuò)展點(diǎn)。只要使用過(guò)Linux系統(tǒng)的讀者瞪慧,應(yīng)該知道 make這個(gè)命令。當(dāng)編譯Linux內(nèi)核及一些軟件源程序時(shí)部念,經(jīng)常要用這個(gè)命令弃酌。Make命令其實(shí)就 是一個(gè)項(xiàng)目管理工具,而Ant所實(shí)現(xiàn)功能與此類(lèi)似印机,像make矢腻,gnumake和nmake這些編譯工具都有 一定的缺陷,但是Ant卻克服了這些工具的缺陷射赛。
jenkins:持續(xù)集成工具
一多柑、安裝前準(zhǔn)備
1.JDK:jdk-8u121-windows-x64
2.jmeter工具:apache-jmeter-3.1
3.ANT工具:apache-ant-1.9.10-bin
4.jenkins工具:jenkins2.109的jenkins.war
5.jmeter插件:JMeterPlugins-Extras-1.4.0、JMeterPlugins-Standard-1.4.0
以上安裝包工具及版本下載地址:https://pan.baidu.com/s/4kWiEEXL
二楣责、軟件安裝
1.JDK的安裝
雙擊JDK安裝包竣灌,選擇安裝路徑(查看jdk安裝路徑:cmd,java -verbose秆麸,我自己安裝在C:\Program Files\Java\jdk1.8.0_121);
1)系統(tǒng)變量→新建 JAVA_HOME 變量 初嘹。
變量值填寫(xiě)jdk的安裝目錄(本人是 C:\Program Files\Java\jdk1.8.0_121);
2)系統(tǒng)變量→尋找 Path 變量→編輯
在變量值最后輸入 %JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;
(注意原來(lái)Path的變量值末尾有沒(méi)有;號(hào)沮趣,如果沒(méi)有屯烦,先輸入;號(hào)再輸入上面的代碼)
3)系統(tǒng)變量→新建 CLASSPATH 變量
變量值填寫(xiě) .;%JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar (注意最前面有一點(diǎn))
系統(tǒng)變量配置完畢
4)檢驗(yàn)是否配置成功 運(yùn)行cmd 輸入 java -version (java 和 -version 之間有空格)
若如圖所示 顯示版本信息 則說(shuō)明安裝和配置成功房铭。
2.jmeter軟件安裝
解壓apache-jmeter-3.1.zip到C:\apache-jmeter-3.1\apache-jmeter-3.1目錄下驻龟。
Jmeter插件的安裝。解壓JMeterPlugins-Extras-1.3.0.zip缸匪、JMeterPlugins-Standard-1.3.0.zip翁狐,將對(duì)應(yīng)ext目錄下的文件拷貝到C:\apache-jmeter-3.1\apache-jmeter-3.1\lib\ext目錄下;
配置jmeter環(huán)境變量:
- 設(shè)置環(huán)境變量凌蔬,新建系統(tǒng)變量在變量名中輸入:JMETER_HOME露懒,變量值中輸入:C:\apache-jmeter-3.1\apache-jmeter-3.1,點(diǎn)擊確定即可砂心。
- 在環(huán)境變量CLASSPATH中添加%JMETER_HOME%\lib\ext\ApacheJMeter_core.jar;%JMETER_HOME%\lib\jorphan.jar;%JMETER_HOME%\lib\logkit-1.2.jar;
在環(huán)境變量Path中添加%JMETER_HOME%\bin -
檢驗(yàn)是否配置成功 運(yùn)行cmd 輸入 jmeter -v (jmeter和 -v 之間有空格)
若如圖所示 顯示版本信息 則說(shuō)明安裝和配置成功懈词。
三、安裝ANT
解壓apache-ant-1.9.10-bin.zip到C:\Program Files (x86)\Java\apache-ant-1.9.10目錄下;
配置ANT環(huán)境變量
1)新建以下環(huán)境變量:
ANT_HOME:C:\Program Files (x86)\Java\apache-ant-1.9.10辩诞,此為你的ANT安裝路徑坎弯;
設(shè)置完成后,點(diǎn)擊"確認(rèn)"來(lái)保存。
2)在環(huán)境變量PATH的最后面添加一下內(nèi)容:
;%ANT_HOME%\bin 注意前面的分號(hào)荞怒,如果PATH中最后沒(méi)有分號(hào)";"的話要加上,有的話就可去除秧秉。
進(jìn)入cmd命令窗口褐桌,在CMD窗口中輸入ant -version,敲擊回城鍵,會(huì)顯示出你安裝的ANT版本,如果成功顯示象迎,說(shuō)明你的配置應(yīng)該是成功了.
四荧嵌、ANT+Jmeter整合
1、將Jmeter所在目錄下extras子目錄里的ant-jmeter-1.1.1.jar復(fù)制到ant所在目錄lib子目錄之下砾淌,ant運(yùn)行時(shí)才能找到
"org.programmerplanet.ant.taskdefs.jmeter.JMeterTask"這個(gè)類(lèi)啦撮,之后可以觸發(fā)Jmeter腳本
2、修改Jmeter的bin目錄下jmeter.properties文件的配置:jmeter.save.saveservice.output_format=xml
3汪厨、建了一個(gè)目錄C:\apache-jmeter-3.1\apache-jmeter-3.1\demo\resultLog赃春,目錄中分別建立了html和jtl兩個(gè)文件夾,之后Ant運(yùn)行之后將jtl中的文件轉(zhuǎn)換成html中
(為什么要?jiǎng)?chuàng)建jtl和html劫乱,可以直接通過(guò)jenkins查看生成的折線圖以及html報(bào)表织中,這兩個(gè)文件夾存放相應(yīng)格式的報(bào)告)
html:存放生成的html報(bào)告
jtl:存放生成的jtl報(bào)告
4、在C:\apache-jmeter-3.1\apache-jmeter-3.1\scripts文件中建立一個(gè)build.xml文件衷戈,build.xml內(nèi)容如下(注意:jmeter下也有一個(gè)build.xml文件狭吼,這個(gè)新建的文件跟jmeter下的不一樣,這個(gè)build.xml要在網(wǎng)上找殖妇,具體如下配置):
build.xml代碼刁笙,注意要修改紅色框框的內(nèi)容
5.將build.xml中的第42行
style="${jmeter.home}/extras/jmeter-results-detail-report_21.xsl">
拷貝以下內(nèi)容將這個(gè)路徑下的jmeter-results-detail-report_21.xsl文件覆蓋,這個(gè)文件說(shuō)明了xsl文件裝換為html文件的一些規(guī)則
<?xml version="1.0"?><xsl:stylesheet xmlns:xsl="[http://www.w3.org/1999/XSL/Transform"](http://www.w3.org/1999/XSL/Transform%22); version="1.0">
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
[http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!--
Stylesheet for processing 2.1 output format test result files
To uses this directly in a browser, add the following to the JTL file as line 2:
<?xml-stylesheet type="text/xsl" href="../extras/jmeter-results-detail-report_21.xsl"?>
and you can then view the JTL in a browser
-->
<xsl:output method="html" indent="yes" encoding="UTF-8" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" />
<!-- Defined parameters (overrideable) --><xsl:param name="showData" select="'n'"/><xsl:param name="titleReport" select="'Load Test Results'"/><xsl:param name="dateReport" select="'date not defined'"/>
<xsl:template match="testResults">
<html>
<head>
<title><xsl:value-of select="$titleReport" /></title>
<style type="text/css">
body {
font:normal 68% verdana,arial,helvetica;
color:#000000;
}
table tr td, table tr th {
font-size: 68%;
}
table.details tr th{
color: #ffffff;
font-weight: bold;
text-align:center;
background:#2674a6;
white-space: nowrap;
}
table.details tr td{
background:#eeeee0;
white-space: nowrap;
}
h1 {
margin: 0px 0px 5px; font: 165% verdana,arial,helvetica
}
h2 {
margin-top: 1em; margin-bottom: 0.5em; font: bold 125% verdana,arial,helvetica
}
h3 {
margin-bottom: 0.5em; font: bold 115% verdana,arial,helvetica
}
.Failure {
font-weight:bold; color:red;
}
img
{
border-width: 0px;
}
.expand_link
{
position=absolute;
right: 0px;
width: 27px;
top: 1px;
height: 27px;
}
.page_details
{
display: none;
}
.page_details_expanded
{
display: block;
display/* hide this definition from IE5/6 */: table-row;
}
</style>
<script language="JavaScript"><![CDATA[
function expand(details_id)
{
document.getElementById(details_id).className = "page_details_expanded";
}
function collapse(details_id)
{
document.getElementById(details_id).className = "page_details";
}
function change(details_id)
{
if(document.getElementById(details_id+"_image").src.match("expand"))
{
document.getElementById(details_id+"_image").src = "collapse.png";
expand(details_id);
}
else
{
document.getElementById(details_id+"_image").src = "expand.png";
collapse(details_id);
}
}
]]></script>
</head>
<body>
<xsl:call-template name="pageHeader" />
<xsl:call-template name="summary" />
<hr size="1" width="95%" align="center" />
<xsl:call-template name="pagelist" />
<hr size="1" width="95%" align="center" />
<xsl:call-template name="detail" />
</body>
</html></xsl:template>
<xsl:template name="pageHeader">
<h1><xsl:value-of select="$titleReport" /></h1>
<table width="100%">
<tr>
<td align="left">Date report: <xsl:value-of select="$dateReport" /></td>
<td align="right">Designed for use with <a href="[http://jmeter.apache.org/"](http://jmeter.apache.org/%22);>JMeter</a> and <a href="[http://ant.apache.org"](http://ant.apache.org%22/);>Ant</a>.</td>
</tr>
</table>
<hr size="1" /></xsl:template>
<xsl:template name="summary">
<h2>Summary</h2>
<table align="center" class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
<tr valign="top">
<th># Samples</th>
<th>Failures</th>
<th>Success Rate</th>
<th>Average Time</th>
<th>Min Time</th>
<th>Max Time</th>
</tr>
<tr valign="top">
<xsl:variable name="allCount" select="count(/testResults/*)" />
<xsl:variable name="allFailureCount" select="count(/testResults/*[attribute::s='false'])" />
<xsl:variable name="allSuccessCount" select="count(/testResults/*[attribute::s='true'])" />
<xsl:variable name="allSuccessPercent" select="$allSuccessCount div $allCount" />
<xsl:variable name="allTotalTime" select="sum(/testResults/*/@t)" />
<xsl:variable name="allAverageTime" select="$allTotalTime div $allCount" />
<xsl:variable name="allMinTime">
<xsl:call-template name="min">
<xsl:with-param name="nodes" select="/testResults/*/@t" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="allMaxTime">
<xsl:call-template name="max">
<xsl:with-param name="nodes" select="/testResults/*/@t" />
</xsl:call-template>
</xsl:variable>
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="$allFailureCount > 0">Failure</xsl:when>
</xsl:choose>
</xsl:attribute>
<td align="center">
<xsl:value-of select="$allCount" />
</td>
<td align="center">
<xsl:value-of select="$allFailureCount" />
</td>
<td align="center">
<xsl:call-template name="display-percent">
<xsl:with-param name="value" select="$allSuccessPercent" />
</xsl:call-template>
</td>
<td align="center">
<xsl:call-template name="display-time">
<xsl:with-param name="value" select="$allAverageTime" />
</xsl:call-template>
</td>
<td align="center">
<xsl:call-template name="display-time">
<xsl:with-param name="value" select="$allMinTime" />
</xsl:call-template>
</td>
<td align="center">
<xsl:call-template name="display-time">
<xsl:with-param name="value" select="$allMaxTime" />
</xsl:call-template>
</td>
</tr>
</table></xsl:template>
<xsl:template name="pagelist">
<h2>Pages</h2>
<table align="center" class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
<tr valign="top">
<th>URL</th>
<th># Samples</th>
<th>Failures</th>
<th>Success Rate</th>
<th>Average Time</th>
<th>Min Time</th>
<th>Max Time</th>
<th></th>
</tr>
<xsl:for-each select="/testResults/*[not(@lb = preceding::*/@lb)]">
<xsl:variable name="label" select="@lb" />
<xsl:variable name="count" select="count(../*[@lb = current()/@lb])" />
<xsl:variable name="failureCount" select="count(../*[@lb = current()/@lb][attribute::s='false'])" />
<xsl:variable name="successCount" select="count(../*[@lb = current()/@lb][attribute::s='true'])" />
<xsl:variable name="successPercent" select="$successCount div $count" />
<xsl:variable name="totalTime" select="sum(../*[@lb = current()/@lb]/@t)" />
<xsl:variable name="averageTime" select="$totalTime div $count" />
<xsl:variable name="minTime">
<xsl:call-template name="min">
<xsl:with-param name="nodes" select="../*[@lb = current()/@lb]/@t" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="maxTime">
<xsl:call-template name="max">
<xsl:with-param name="nodes" select="../*[@lb = current()/@lb]/@t" />
</xsl:call-template>
</xsl:variable>
<tr valign="top">
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="$failureCount > 0">Failure</xsl:when>
</xsl:choose>
</xsl:attribute>
<td>
<xsl:if test="$failureCount > 0">
<a><xsl:attribute name="href">#<xsl:value-of select="$label" /></xsl:attribute>
<xsl:value-of select="$label" />
</a>
</xsl:if>
<xsl:if test="0 >= $failureCount">
<xsl:value-of select="$label" />
</xsl:if>
</td>
<td align="center">
<xsl:value-of select="$count" />
</td>
<td align="center">
<xsl:value-of select="$failureCount" />
</td>
<td align="right">
<xsl:call-template name="display-percent">
<xsl:with-param name="value" select="$successPercent" />
</xsl:call-template>
</td>
<td align="right">
<xsl:call-template name="display-time">
<xsl:with-param name="value" select="$averageTime" />
</xsl:call-template>
</td>
<td align="right">
<xsl:call-template name="display-time">
<xsl:with-param name="value" select="$minTime" />
</xsl:call-template>
</td>
<td align="right">
<xsl:call-template name="display-time">
<xsl:with-param name="value" select="$maxTime" />
</xsl:call-template>
</td>
<td align="center">
<a href="">
<xsl:attribute name="href"><xsl:text/>javascript:change('page_details_<xsl:value-of select="position()" />')</xsl:attribute>
<img src="expand.png" alt="expand/collapse"><xsl:attribute name="id"><xsl:text/>page_details_<xsl:value-of select="position()" />_image</xsl:attribute></img>
</a>
</td>
</tr>
<tr class="page_details">
<xsl:attribute name="id"><xsl:text/>page_details_<xsl:value-of select="position()" /></xsl:attribute>
<td colspan="8" bgcolor="#FF0000">
<div align="center">
<b>Details for Page "<xsl:value-of select="$label" />"</b>
<table bordercolor="#000000" bgcolor="#2674A6" border="0" cellpadding="1" cellspacing="1" width="95%">
<tr>
<th>Thread</th>
<th>Iteration</th>
<th>Time (milliseconds)</th>
<th>Bytes</th>
<th>Success</th>
</tr>
<xsl:for-each select="../*[@lb = $label and @tn != $label]">
<tr>
<td><xsl:value-of select="@tn" /></td>
<td align="center"><xsl:value-of select="position()" /></td>
<td align="right"><xsl:value-of select="@t" /></td>
<!-- TODO allow for missing bytes field -->
<td align="right"><xsl:value-of select="@by" /></td>
<td align="center"><xsl:value-of select="@s" /></td>
</tr>
</xsl:for-each>
</table>
</div>
</td>
</tr>
</xsl:for-each>
</table></xsl:template>
<xsl:template name="detail">
<xsl:variable name="allFailureCount" select="count(/testResults/*[attribute::s='false'])" />
<xsl:if test="$allFailureCount > 0">
<h2>Failure Detail</h2>
<xsl:for-each select="/testResults/*[not(@lb = preceding::*/@lb)]">
<xsl:variable name="failureCount" select="count(../*[@lb = current()/@lb][attribute::s='false'])" />
<xsl:if test="$failureCount > 0">
<h3><xsl:value-of select="@lb" /><a><xsl:attribute name="name"><xsl:value-of select="@lb" /></xsl:attribute></a></h3>
<table align="center" class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
<tr valign="top">
<th>Response</th>
<th>Failure Message</th>
<xsl:if test="$showData = 'y'">
<th>Response Data</th>
</xsl:if>
</tr>
<xsl:for-each select="/testResults/*[@lb = current()/@lb][attribute::s='false']">
<tr>
<td><xsl:value-of select="@rc | @rs" /> - <xsl:value-of select="@rm" /></td>
<td><xsl:value-of select="assertionResult/failureMessage" /></td>
<xsl:if test="$showData = 'y'">
<td><xsl:value-of select="./binary" /></td>
</xsl:if>
</tr>
</xsl:for-each>
</table>
</xsl:if>
</xsl:for-each>
</xsl:if></xsl:template>
<xsl:template name="min">
<xsl:param name="nodes" select="/.." />
<xsl:choose>
<xsl:when test="not($nodes)">NaN</xsl:when>
<xsl:otherwise>
<xsl:for-each select="$nodes">
<xsl:sort data-type="number" />
<xsl:if test="position() = 1">
<xsl:value-of select="number(.)" />
</xsl:if>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose></xsl:template>
<xsl:template name="max">
<xsl:param name="nodes" select="/.." />
<xsl:choose>
<xsl:when test="not($nodes)">NaN</xsl:when>
<xsl:otherwise>
<xsl:for-each select="$nodes">
<xsl:sort data-type="number" order="descending" />
<xsl:if test="position() = 1">
<xsl:value-of select="number(.)" />
</xsl:if>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose></xsl:template>
<xsl:template name="display-percent">
<xsl:param name="value" />
<xsl:value-of select="format-number($value,'0.00%')" /></xsl:template>
<xsl:template name="display-time">
<xsl:param name="value" />
<xsl:value-of select="format-number($value,'0 ms')" /></xsl:template>
</xsl:stylesheet>
6谦趣、進(jìn)入Dos窗口疲吸,切換到build.xml路徑(我的是C:\apache-jmeter-3.1\apache-jmeter-3.1\extras),輸入命令ant敲回車(chē)蔚润,運(yùn)行結(jié)束會(huì)有success信息提示
7磅氨、查看報(bào)告:
1.在\demo\resultLog\html路徑下查看html報(bào)告如下
五、Jenkins的安裝
1嫡纠,接下來(lái)安裝jenkins烦租,下載war包
放到tomcat下的webapps下:
2,查看端口命令:
(1)netstat -ano:顯示機(jī)器的端口占用情況
(2)netstat -ano|findstr “提示的端口”:顯示某個(gè)端口的占用情況
(3)tasklist|findstr “pid”:根據(jù)pid找到進(jìn)程名稱(chēng)
疑惑:查找到的端口具體每列代表什么意思踱侣?后面linux學(xué)習(xí)總結(jié)
3,修改tomcat默認(rèn)的端口號(hào)port(tomcat下的conf中的server.xml):
4,重啟tomcat,打開(kāi)地址:http://localhost:8081/jenkins
5,打開(kāi)的頁(yè)面要求粘貼密碼擅腰,具體路徑在:C:\Users\dell.jenkins\secrets\initialAdminPassword
6,進(jìn)入jenkins后選擇推薦的插件安裝。
7取刃,創(chuàng)建管理員用戶:
用戶名:root
密碼:C:\Users\dell.jenkins\secrets\initialAdminPassword中復(fù)制的內(nèi)容
全名:默認(rèn)跟用戶名同名
電子郵件:404423741@qq.com
保存并完成崩侠,顯示:
六、配置
1、jenkins系統(tǒng)設(shè)置->管理插件->可選插件肌稻,搜索Performance plugin(Jmeter報(bào)告需要),安裝此插件
2嘶卧、因?yàn)樾枰玫紸NT和JDK专甩,所以需要在jenkins中添加插件种樱,選擇點(diǎn)擊“系統(tǒng)管理”俐镐,之后在全局工具配置的界面看到ant和jdk選項(xiàng)无宿,然后將自己本地的ANT和JDK地址填寫(xiě)上
3蹂午、配置、測(cè)試郵件1
在系統(tǒng)設(shè)置中找到Jenkins Locaction項(xiàng)填入Jenkins URL和系統(tǒng)管理員郵件地址彬碱,系統(tǒng)管理員郵件地址一定要配置豆胸,否則發(fā)不了郵件通知。因?yàn)猷]件通知都是由系統(tǒng)管理員的郵箱發(fā)出來(lái)的
按照如圖所示設(shè)置即可巷疼,本處設(shè)置的是QQ企業(yè)郵箱的服務(wù)晚胡,其他郵箱按照類(lèi)似設(shè)置即可
首先在度娘中找到SMTP服務(wù)器地址和端口號(hào)及設(shè)置QQ郵箱的POP3/SMTP服務(wù)
測(cè)試郵件發(fā)送成功之后,Extended E-mail Notification參照上面的設(shè)置即可嚼沿。(注意:必須配置估盘,否則后期項(xiàng)目構(gòu)建發(fā)送郵件將失敗)
4骡尽、創(chuàng)建job:
構(gòu)建步驟:
點(diǎn)擊保存遣妥,立即構(gòu)建,成功:
具體成功或者失敗原因可看控制臺(tái)輸出:
html報(bào)告:
疑問(wèn):
1攀细,配置的發(fā)送郵件這次沒(méi)有用到燥透,不知道什么時(shí)候開(kāi)啟,發(fā)送辨图,具體后面琢磨班套。
2,html報(bào)告里面pages中有三個(gè)請(qǐng)求:Sample1故河,Sample2吱韭,HTTP請(qǐng)求,其實(shí)HTTP請(qǐng)求才是我要測(cè)試的腳本鱼的,但是顯示3個(gè)理盆,上面Sample1,Sample2顯示的什么意思凑阶?相關(guān)的配置在哪里猿规?
3,如果只對(duì)于jmeter+ant集成的話宙橱,怎么看html的報(bào)告姨俩,在這個(gè)文章中jmeter+ant集成和jmeter+ant+jenkins集成的html報(bào)告成一樣的了蘸拔。