1. 程式人生 > >Jmeter+Maven+Jenkins的搭建筆記

Jmeter+Maven+Jenkins的搭建筆記

time youdao eclips 集成 3.3 核心 target dao project

關於Jmeter的持續集成,首先先談談Jmeter+Maven的集成。

1、使用idea或者eclipse創建一個maven項目

2、在test下創建一個Jmeter目錄

技術分享圖片

3、將jmeter腳本放入jmeter這個目錄下

4、把本地的jmeter屬性文件放入到jmeter目錄下,這裏需註意,需要修改一些屬性

(1)jmeter.save.saveservice.output_format=xml

5、在test文件下創建一個resources文件,並將它在項目屬性中設置為Test resources,在將xsl報告放入進去

技術分享圖片

6、設置Maven的pom文件

<!--設置報告生成的路徑-->
<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>
</properties>

<build>
<plugins>
<plugin>
<!-- 核心插件,用來執行jmx腳本,版本號對應的jmeter版本可在此地址查詢 https://github.com/jmeter-maven-plugin/jmeter-maven-plugin/blob/master/CHANGELOG.md-->
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>2.2.0</version>
<configuration>

<!-- 設置jmeter生成結果文件格式-->
<resultsFileFormat>xml</resultsFileFormat>
<!-- 設置忽略失敗是否停止運行-->
<ignoreResultFailures>true</ignoreResultFailures>
<!--設置結果是否有時間戳-->
<testResultsTimestamp>false</testResultsTimestamp>
<testFilesIncluded>
<!-- //指定運行的jmeter腳本 -->
<jMeterTestFile>youdao.jmx</jMeterTestFile>
</testFilesIncluded>
<!-- 指定jtl生成目錄 -->
<resultsDirectory>${jmeter.result.jtl.dir}</resultsDirectory>
</configuration>
<executions>
<execution>
<id>jmeter-tests</id>
<phase>verify</phase>
<!--腳本所在的文件夾 -->
<goals>
<goal>jmeter</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<!--根據xsl模版把jtl文件轉換成html-->
<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.shanhe.me.xsl</stylesheet>
<outputDir>${jmeter.result.html.dir}</outputDir>
<!-- 把jtl格式轉傳承html -->
<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>
備註:這裏遇到過幾個問題
1、如果jmeter4.0版本是無法轉換HTML報告的,使用
jmeter-maven-plugin插件無法修改jmeter的屬性文件,目前還沒有找到解決辦法,所以我使用的是3.3版本
2、如果提示xsl文件未找到,那就是找不到啟動的腳本,需查看技術分享圖片技術分享圖片
這裏如果運行的話,運行的是jmeter目錄下的youdao.jmx文件

7、idea中運行maven,找到頂部的運行配置
技術分享圖片

點擊+號找到maven後添加,在Command line:下輸入verify保存即可

技術分享圖片

8、點擊運行,會生成一個target文件,運行後的html結果在此目錄下,此目錄是可以自己在pom文件裏添加的
技術分享圖片
9、結果展示,此報告也可以二次重寫
技術分享圖片

 




Jmeter+Maven+Jenkins的搭建筆記