使用Maven Jenkins和JMeter自动化测试
?
有兩個插件能夠實現在Maven build集成Jmeter測試,?jmeter-maven-plugin?和?chronos-maven-plugin.?選擇哪一個取決于情況,下面是一些判斷標準:
第一第二條兩個都滿足,jmeter-maven-plugin可以在無圖形情況下使用一個簡單的附加依賴項kg.apc:jmeter-plugins直接使用使用JMeter,這點是?jmeter-chronos-maven-plugin沒有的。
下面是一段來自?jmeter-maven-example的配置:
<plugin>
? <groupId>com.lazerycode.jmeter</groupId>
? <artifactId>jmeter-maven-plugin</artifactId>
? <version>1.8.1</version>
? <configuration>
??? <!--
?????? By default the test results are saved in a file?
?????? /target/jmeter/results/<testname>-<timestamp>.jtl
?????? Further processing is easier without timestamp though.
??? -->
??? <testResultsTimestamp>false</testResultsTimestamp>
?
??? <!--
?????? To simplify debugging, it is advisable to adapt the loglevel.
?????? The jmeter logs are written to the file jmeter.log.
??? -->
??? <overrideRootLogLevel>DEBUG</overrideRootLogLevel>
?
??? <!--
?????? By default, the console output during a jmeter test run is suppressed.
?????? We want to display the progress using the listener "Generate Summary Results"
?????? (which periodically prints stats to stdout). Therefore we have to make sure,
?????? that the jmeter output is not suppressed.
??? -->
??? <suppressJMeterOutput>false</suppressJMeterOutput>
?
??? <!--
? ?????If tests fail (e.g. a http-request running into a timeout), the corresponding maven
?????? goal also fails (and subsequent goals aren't executed anymore). We want to create graphs
?????? from test-results, no matter if some requests failed or not, so we ignore jmeter failures.
??? -->
??? <ignoreResultFailures>true</ignoreResultFailures>
? </configuration>
? <dependencies>
??? <dependency>
????? <groupId>kg.apc</groupId>
????? <artifactId>jmeter-plugins</artifactId>
????? <version>1.0.0</version>
????? <exclusions>
???????? <!--
??????????? Unfortunately some transitive dependencies cannot be found on mvncentral
??????????? and we have to explicitly exclude them.
??????????? For a complete list, see https://github.com/mlex/jmeter-maven-example/
?? ?????-->
??????? <exclusion>
??????????? <groupId>kg.apc</groupId>
??????????? <artifactId>perfmon</artifactId>
??????? </exclusion>
??????? <!-- ... -->
?
??????? <!--
??????????? Because of a bug in the jmeter-maven-plugin (see
??????????? https://github.com/Ronnie76er/jmeter-maven-plugin/issues/77) we have to
??????????? exclude jmeter dependencies here, too.
??????? -->
??????? <exclusion>
??????????? <groupId>org.apache.jmeter</groupId>
??????????? <artifactId>jorphan</artifactId>
??????? </exclusion>
??????? <!-- ... -->
????? </exclusions>
??? </dependency>
? </dependencies>
</plugin>
這個測試文件必須放在?/src/test/jmeter,您可以編輯和執行測試。
測試環境可以是各種,這里結合?Jenkins中創建一個Job,允 許一次點擊就可以執行JMeter的測試,首先要使用Maven的屬性和配置文件。下面示例項目中定義了兩種不同的Maven配置文件,一個用于本地執 行,一個用于從jenkins執行。 Maven的特性是通過userProperties選項傳遞到JMeter的。
<profiles>
? <profile>
??? <id>local</id>
??? <properties>
????? <performancetest.webservice.host>localhost</performancetest.webservice.host>
????? <performancetest.webservice.port>8080</performancetest.webservice.port>
??? </properties>
? </profile>
? <profile>
??? <id>jenkins</id>
??? <properties>
????? <performancetest.webservice.host>my.test.system</performancetest.webservice.host>
????? <performancetest.webservice.port>80</performancetest.webservice.port>
??? </properties>
? </profile>
? <build>
??? <plugins>
????? <plugin>
??????? <groupId>com.lazerycode.jmeter</groupId>
??????? <artifactId>jmeter-maven-plugin</artifactId>
??????? <version>1.8.1</version>
??????? <configuration>
????????? <propertiesUser>
??????????? <webservice.host>${performancetest.webservice.host}</webservice.host>
??????????? <webservice.port>${performancetest.webservice.port}</webservice.port>
????????? </propertiesUser>
??????? </configuration>
????? </plugin>
??? </plugins>
? </build>
</plugin>
?
使用Jenkins-CI進行JMeter tests
現在,我們已經為各種環境下制作了不同的Maven配置文件,一個合適的jenkins作業的配置僅僅需要一小步。參數化的構建版 本是jenkins的另一個不錯的功能,針對JMeter的測試非常有用。參數可用于例如,允許用戶定義負載測試的大小(即:線程數和迭代的次數)。
?
報表
使用jmeter-graph-maven-plugin集合Jmeter的CMDRunner工具,可以讓我們在Maven Build中輸出圖形結果。
https://github.com/codecentric/jmeter-graph-maven-plugin
?
轉載于:https://www.cnblogs.com/zhengah/p/5207065.html
總結
以上是生活随笔為你收集整理的使用Maven Jenkins和JMeter自动化测试的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux下怎么做秒执行任务
- 下一篇: apache 一个站点配置多个域名