背景:
首先用jmeter錄制或者書寫性能測試的腳本,用maven添加相關(guān)依賴,把性能測試的代碼提交到github,在jenkins配置git下載性能測試的代碼,配置運(yùn)行腳本和測試報(bào)告,配置運(yùn)行失敗自動(dòng)發(fā)郵件通知,這樣一來性能測試的job配置完成。接著,把性能測試的job配置成開發(fā)job的下游job,一旦開發(fā)有了新的代碼提交運(yùn)行開發(fā)自己的job后,就會自動(dòng)觸發(fā)我們性能測試的job。這樣我們就實(shí)現(xiàn)了接口性能測試的全自動(dòng)化,我們只需要關(guān)注測試失敗的郵件!【文末有配套視頻教程和免費(fèi)的測試資料】
1、環(huán)境搭建
- 下載安裝 jdk &eclipse。
- 下載安裝jenkins。
- 下載maven 并進(jìn)行解壓。
- 下載jmeter并解壓。
2、準(zhǔn)備性能測試的腳本
- 啟動(dòng) jmeter (雙擊 jmeter解壓目錄下的bin\jmeter.bat)。
- 用jmeter書寫test cases,并導(dǎo)出(推薦)。?
- 或者你可以用jmeter錄制腳本,確保運(yùn)行通過后,導(dǎo)出。
- 當(dāng)然你可以選擇用badboy錄制腳本,確保運(yùn)行通過后,導(dǎo)出。(badboy支持ie瀏覽器的錄制)
- 也可以使用chrome插件(BlazeMeter)下載鏈接:https://www.chromefor.com/blazemeter-the-continuous-testing-platform_v3-2-0/ ? ? ?
?注意:如果導(dǎo)出不了腳本,是版本原因,下載最新的版文本即可
3、為性能測試腳本創(chuàng)建maven project
打開eclipse,并創(chuàng)建一個(gè) maven project。
在src/test/目錄下創(chuàng)建jmeter文件夾把準(zhǔn)備好的性能測試的腳本復(fù)制到這個(gè)文件夾下。
?
在src/test/目錄下創(chuàng)建resource文件夾,并把測試模板(E:\apache-jmeter-3.2\apache-jmeter-3.2\extras的如下文件)復(fù)制到這個(gè)resource文件下。
并把如下文件從apache-jmeter-3.2\bin目錄下復(fù)制到src/test/jmeter文件里。
在maven腳本里(即pom.xml)添加jmeter-maven-plugin相關(guān)依賴如下:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.performance.test</groupId>
<artifactId>PushNotificationPerformanceTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>PushNotificationPerformanceTest</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jmeter.result.jtl.dir>${project.build.directory}\jmeter\results</jmeter.result.jtl.dir>
<jmeter.result.html.dir>${project.build.directory}\jmeter\html</jmeter.result.html.dir>
<jmeter.result.html.dir1>${project.build.directory}\jmeter\html1</jmeter.result.html.dir1>
<ReportName>TestReport</ReportName>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>2.3.0</version>
<executions>
<execution>
<id>jmeter-tests</id>
<goals>
<goal>jmeter</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xml-maven-plugin</artifactId>
<version>1.0-beta-3</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>transform</goal>
</goals>
</execution>
</executions>
<configuration>
<transformationSets>
<transformationSet>
<dir>${jmeter.result.jtl.dir}</dir>
<stylesheet>src\test\resources\jmeter-results-detail-report_21.xsl</stylesheet>
<outputDir>${jmeter.result.html.dir}</outputDir>
<fileMappers>
<fileMapper
implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
<targetExtension>html</targetExtension>
</fileMapper>
</fileMappers>
</transformationSet>
<transformationSet>
<dir>${jmeter.result.jtl.dir}</dir>
<stylesheet>src\test\resources\jmeter-results-report_21.xsl</stylesheet>
<outputDir>${jmeter.result.html.dir1}</outputDir>
<fileMappers>
<fileMapper
implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
<targetExtension>html</targetExtension>
</fileMapper>
</fileMappers>
</transformationSet>
</transformationSets>
</configuration>
<!-- using XSLT 2.0 -->
<dependencies>
<dependency>
<groupId>net.sf.saxon</groupId>
<artifactId>saxon</artifactId>
<version>8.7</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
4、在eclipse運(yùn)行性能測試腳本
選中性能測試的project 右擊,然后在下拉框中選擇run as -》maven build ,然后在彈出的對話框的Goals 寫上verify,最hou點(diǎn)擊run(如下圖)。?
運(yùn)行后會有測試結(jié)果文件如下圖
5、在jenkins 運(yùn)行性能測試腳本并配置測試結(jié)果
在jenkins上安裝如下插件:
- Maven Integration plugin Maven,用于jenkins可以創(chuàng)建maven job ;
- Git plugin ,用于從github下載性能測試的代碼;
- Performance plugin ,用于顯示測試報(bào)告;
- HTML Publisher plugin ,用于顯示相關(guān)接口測試結(jié)果的報(bào)告。
1、jenkins環(huán)境準(zhǔn)備(全局工具配置)
目錄:系統(tǒng)管理-->全局工具配置
1)配置jdk地址
maven配置:
2、配置maven工程
1) 在jenkins創(chuàng)建maven job
2)在jenkins上配置運(yùn)行腳本
首先在工程里點(diǎn)擊配置選項(xiàng)
3)在jenkins上配置測試結(jié)果報(bào)告
4)配置完了,點(diǎn)擊buid now,開始運(yùn)行,結(jié)果如下:
下面的報(bào)告是更換了報(bào)告的模板,具體實(shí)現(xiàn)百度
ps:
關(guān)于顯示測試結(jié)果:
1. 如在jenkins使用html publisher查看報(bào)告時(shí),發(fā)現(xiàn)顯示不美觀,不全的現(xiàn)象,很多東西顯示不了,解決這個(gè)問題可以在jenkins系統(tǒng)管理中輸入以下腳本運(yùn)行,就可以解決這個(gè)問題了
System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "")
更多解決方法:https://zhuanlan.zhihu.com/p/280809752.html結(jié)果好多為空,請把jmeter.property的相應(yīng)的false改為true。
#測試報(bào)告信息展示
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=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
# Only available with HttpClient4
jmeter.save.saveservice.sent_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
最后感謝每一個(gè)認(rèn)真閱讀我文章的人,禮尚往來總是要有的,雖然不是什么很值錢的東西,如果你用得到的話可以直接拿走:
同時(shí),在這我為大家準(zhǔn)備了一份軟件測試視頻教程(含面試、接口、自動(dòng)化、性能測試等),就在下方,需要的可以直接去觀看,也可以直接【點(diǎn)擊文末小卡片免費(fèi)領(lǐng)取資料文檔】
軟件測試視頻教程觀看處:
【2024最新版】Python自動(dòng)化測試15天從入門到精通,10個(gè)項(xiàng)目實(shí)戰(zhàn),允許白嫖。。。文章來源:http://www.zghlxwxcb.cn/news/detail-814878.html
文章來源地址http://www.zghlxwxcb.cn/news/detail-814878.html
到了這里,關(guān)于Jmeter+Maven+jenkins+eclipse搭建自動(dòng)化測試平臺的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!