編者按:html
ant有兩個分支版本:1.9x支持的是java5,1.10.x支持的是java8的版本。
這裏咱們選擇apache-ant-1.10.1-bin.tar.gz
的版本。java
cd /usr/local/src wget http://mirrors.tuna.tsinghua.edu.cn/apache//ant/binaries/apache-ant-1.10.1-bin.tar.gz tar -zxf apache-ant-1.10.1-bin.tar.gz mv apache-ant-1.10.1 /data/app/ ln -s /data/app/apache-ant-1.10.1 /data/app/ant ### 增長環境變量 cat >>/etc/bashrc<<EOF export ANT_HOME=/data/app/ant export PATH=$ANT_HOME/bin/:$PATH EOF source /etc/bashrc
檢查node
ant -v Apache Ant(TM) version 1.10.1 compiled on February 2 2017 Trying the default build file: build.xml Buildfile: build.xml does not exist! Build failed
cd /usr/local/src wget http://mirror.bit.edu.cn/apache//jmeter/binaries/apache-jmeter-3.3.tgz tar -zxf apache-jmeter-3.3.tgz mv apache-jmeter-3.3 /data/app/ ln -s /data/app/apache-jmeter-3.3 /data/app/jmeter ### 配置環境變量 cat >> /etc/bashrc<<EOF export JMETER_HOME=/data/app/jmeter export CLASSPATH=$JMETER_HOME/lib/ext/ApacheJMeter_core.jar:$JMETER_HOME/lib/jorphan.jar:$JMETER_HOME/lib/logkit-2.0.jar:$CLASSPATH export PATH=$JMETER_HOME/bin/:$PATH EOF
cp /data/app/jmeter/lib/serializer-2.7.2.jar /data/app/ant/lib/ cp /data/app/jmeter/lib/xalan-2.7.2.jar /data/app/ant/lib/
taskdef class org.programmerplanet.ant.taskdefs.jmeter.JMeterTask cannot be found using the classloader AntClassLoader[]
解決辦法:git
cp /data/app/jmeter/extras/ant-jmeter-1.1.1.jar /data/app/ant/lib/
jmeter-log.log
的日誌文件,日誌文件配置在/data/app/jmeter/bin/log4j2.xml
。解決辦法:shell
touch /data/app/jmeter/bin/jmeter.log
chown -R jenkins.jenkins /data/app/ant/* chown -R jenkins.jenkins /data/app/jmeter/*
cd /data/app/jmeter/build/ vim 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="/data/app/jmeter" /> <!-- jmeter生成jtl格式的結果報告的路徑--> <property name="jmeter.result.jtl.dir" value="/data/app/jmeter/report/jtl" /> <!-- jmeter生成html格式的結果報告的路徑--> <property name="jmeter.result.html.dir" value="/data/app/jmeter/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" /> <!-- 接收測試報告的郵箱 --> <property name="mail_to" value="niuhengbo@sina.cn" /> <!-- 電腦地址 --> <property name="ComputerName" value="test.niu" /> <target name="all"> <antcall target="test" /> <antcall target="report" /> </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="/data/db/jenkins/workspace/jm" includes="*.jmx" /> </jmeter> </target> <target name="report"> <!-- <xslt in="${jmeter.result.jtlName}" out="${jmeter.result.htmlName}" style="${jmeter.home}/extras/jmeter-results-detail-report_21.xsl" /> --> <xslt in="${jmeter.result.jtlName}" out="${jmeter.result.htmlName}" style="${jmeter.home}/extras/jmeter.results.shanhe.me.xsl" /> <!-- 由於上面生成報告的時候,不會將相關的圖片也一塊兒拷貝至目標目錄,因此,須要手動拷貝 --> <copy todir="${jmeter.result.html.dir}"> <fileset dir="${jmeter.home}/extras"> <include name="collapse.png" /> <include name="expand.png" /> </fileset> </copy> </target> <!-- 發送郵件 --> </project>
jmeter-results-detail-report_21.xsl
是默認的報告模板因爲信息不全,推薦更換成jmeter.results.shanhe.me.xsl
下載地址在文章最後。/data/app/jmeter/bin/jmeter.properties
。jmeter.save.saveservice.output_format=csv
: 將csv更改成xml。在文件的末尾增長如何優化配置apache
jmeter.save.saveservice.data_type=true jmeter.save.saveservice.label=true jmeter.save.saveservice.response_code=true # response_data is not currently supported for CSV output jmeter.save.saveservice.response_data=true # Save ResponseData for failed samples jmeter.save.saveservice.response_data.on_error=false # Report more error info message jmeter.save.saveservice.assertion_results_failure_message=true jmeter.save.saveservice.response_message=true jmeter.save.saveservice.successful=true jmeter.save.saveservice.thread_name=true jmeter.save.saveservice.time=true jmeter.save.saveservice.subresults=true jmeter.save.saveservice.assertions=true jmeter.save.saveservice.latency=true jmeter.save.saveservice.connect_time=true jmeter.save.saveservice.samplerData=true jmeter.save.saveservice.responseHeaders=true jmeter.save.saveservice.requestHeaders=true jmeter.save.saveservice.encoding=false jmeter.save.saveservice.bytes=true jmeter.save.saveservice.url=true jmeter.save.saveservice.filename=true jmeter.save.saveservice.hostname=true jmeter.save.saveservice.thread_counts=true jmeter.save.saveservice.sample_count=true jmeter.save.saveservice.idle_time=true
cd /data/app/jmeter/build/ ant
Buildfile: /data/app/apache-jmeter-3.3/build/build.xml all: test: [jmeter] Executing test plan: /data/db/jenkins/workspace/jm/test.jmx ==> /data/app/jmeter/report/jtl/TestReport201801250234.jtl [jmeter] Creating summariser <summary> [jmeter] Created the tree successfully using /data/db/jenkins/workspace/jm/test.jmx [jmeter] Starting the test @ Thu Jan 25 14:34:18 CST 2018 (1516862058701) [jmeter] Waiting for possible Shutdown/StopTestNow/Heapdump message on port 4445 [jmeter] summary = 4 in 00:00:01 = 6.9/s Avg: 96 Min: 28 Max: 239 Err: 0 (0.00%) [jmeter] Tidying up ... @ Thu Jan 25 14:34:20 CST 2018 (1516862060127) [jmeter] ... end of run report: [xslt] Processing /data/app/jmeter/report/jtl/TestReport201801250234.jtl to /data/app/jmeter/report/html/TestReport201801250234.html [xslt] Loading stylesheet /data/app/jmeter/extras/jmeter.results.shanhe.me.xsl BUILD SUCCESSFUL Total time: 4 seconds
jenkins的安裝我就不說了,能夠參考之前我寫的文章。vim
第一步:配置ant路徑位置
位置:全局配置 --> Global Tool Configuration
bash
建立一個自由風格的軟件項目
服務器
將jmeter的測試文件放置在git倉庫中。
app
增長一個ant構建項目:
執行構建查看輸出結果
jmeter.results.shanhe.me.xsl-下載地址
接口自動化-步驟、遇到的問題及解決方法
jmeter學習筆記(一)-jmeter html測試報告
taskdef class org.programmerplanet.ant.taskdefs.jmeter.JMeterTask cannot be found using the classloader AntClassLoader[]
解決辦法
cp /data/app/jmeter/extras/ant-jmeter-1.1.1.jar /data/app/ant/lib/