轉帖|行業資訊|編輯:龔雪|2016-03-09 13:17:16.000|閱讀 246 次
概述:本文主要介紹如何進行高性能自動化測試的環境搭建,重點介紹如何部署 Jenkins Server, Chef Server, Chef Client, NTP Server, NTP Client, Yum Server,NFS Server, NFS Client 和 SSH 免密碼登錄,從而幫助讀者了解如何在項目里進行高性能自動化測試的環境部署。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
部署 SSH 免密碼登錄和 Report Server
在進行高性能自動化測試的過程中,復制/移動最終的測試結果到 Report Server 時會用到 scp,因為它比較安全。但如果每次都要在 script 里輸入密碼,就比較煩了。以下操作將介紹生成密匙對的步驟,從而完成 SSH 免密碼登錄的配置,方便測試結果被安全迅速的傳送到 Report Server。
如何在實際項目里進行高性能自動化測試
根據以上步驟,您就可以搭建一套可以實現高性能自動化測試的測試環境,下面介紹下如何在搭建的環境里進行高性能測試。
并行執行多個 Chef Client 上的測試
在第二部分介紹了如何部署 Chef Server 和 Chef Client,在此向讀者介紹下如何在 Chef Server 上并行的執行多個 Chef Client 上的測試任務,通過在多個 node 上進行分布式的并發測試,從而減少測試時間,提高測試效率。
在此舉例下如何并行的喚起多個 Chef Client 上的 testing,Shell 腳本如下:
<script> #Invoke all chef clients for QAF by multiple thread echo start: `date`; start=`date +%s`; #for function is used to invoke all Chef Clients to test for ((i=1;i<=${#ip[@]};i++)) do { #knife bootstrap command is used to start testing in the Chef Clients knife bootstrap ${ip[$i-1]} -x root --sudo -r "role[client_QAF]" }& Done #wait command is used to wait for all the testing finished in the Chef Clients wait echo end: `date`; end=`date +%s`; #time is used to analysis the testing time time=$[ end -start ]; </script>
shell 腳本自動歸集測試報告
由于測試是分布式的在多個 node 上進行的,所以測試完成后,需要將每個 Chef Client 上的測試報告歸集到一起的,在這里就用到了第二部分所介紹的 NFS 自動收集所有 node 上的報告。
在此舉例下如何收集多個 Chef Client 上的 testing report,Shell 腳本如下:
<script> #!/bin/bash range=$1 #initial report folder rm -rf /root/$range/workspace/com.spss.qa.automation/html/* rm -rf /root/$range/workspace/com.spss.qa.automation/test-reports/* #gather report if [ $range = "3.0" ] then cp -rf /root/share/test-reports/3.0/* /root/$range/workspace/com.spss.qa.automation/test-reports cp -rf /root/share/test-reports/2.0/* /root/$range/workspace/com.spss.qa.automation/test-reports else cp -rf /root/share/test-reports/$range/* /root/$range/workspace/com.spss.qa.automation/test-reports fi </script>
發布測試 report
所有的測試報告都被收集到 Report server 上后,用 Ant 腳本產生 Html report。Ant 腳本如下:
<script> <target name="report"> <junitreport todir="${basedir}/test-reports"> <fileset dir="${basedir}/test-reports"> <include name="TEST-*.xml" /> </fileset> <report format="frames" todir="${basedir}/html" /> </junitreport> </target> </script>
然后通過第二部分介紹的 SSH 免密碼登錄將產生的測試 report 發布到 Jenkins 上指定的路徑上去,Shell 腳本如下:
<script> #pubilsh report to //9.30.214.85:8080/testStage_$version mkdir -p /root/apache-tomcat-7.0.59/webapps/testStage_$version cp -rf /root/share/html/$range/* /root/apache-tomcat-7.0.59/webapps/testStage_$version cd /root/apache-tomcat-7.0.59/bin ./startup.sh #publish report to build server cd /root/workspace/testStage/share/html/$range/ scp -r * root@9.30.214.84:/$report_path </script>
發送測試結果郵件
測試進行完成后,Jenkins 會自動給組里人員發送測試報告郵件,讀者可以按照以下在 Jenkins 里配置郵件收件人和郵件標題。
實際項目里收到的測試結果郵件如下:
項目里遇到的問題以及解決辦法
在此,簡單列舉下如何處理環境異常的情況:NFS Server 和 NFS Client 之間通信斷掉。當節假日來臨或者 IT 部門維修 VM 的時候,會遇到 VM 被關機的情況,人為將 VM 開機后,NFS Server 和 NFS Client 之間的通信也已經被斷掉了。這時候,我們需要做 2 個步驟解決通信被斷掉的問題:
結束語
本文探索了如何搭建高性能自動化測試環境, 您可以根據本文介紹的方法,搭建環境實現在多個 Chef Client 上并行的進行自動化測試,從而減少測試執行時間,縮短測試周期,提高測試效率,實現高性能自動化測試。
原文轉載自:
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn