设为首页 收藏本站
查看: 990|回复: 0

[经验分享] 使用Maven Jenkins和JMeter自动化测试

[复制链接]

尚未签到

发表于 2018-1-7 19:50:56 | 显示全部楼层 |阅读模式

  有两个插件能够实现在Maven build集成Jmeter测试, jmeter-maven-plugin 和 chronos-maven-plugin. 选择哪一个取决于情况,下面是一些判断标准:

  • 该插件不应该依赖于本地JMeter的安装。
  • 它必须能够从命令行启动JMeter测试(无GUI)。
  • JMeter的图形用户界面也应该通过插件(例如,通过一个单独的Maven目标)直接实现。
  • 它包含JMeter的插件。
  • 该插件应该产生有意义的报告。
  第一第二条两个都满足,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

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-432705-1-1.html 上篇帖子: 记录走过的点点滴滴分享经验,传播知识,一个码农的幸福生活。 下篇帖子: jmeter+ant+jenkins接口自动环境搭建
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表