专栏首页DevOps持续集成Ant+Jmeter批量接口测试实践

Ant+Jmeter批量接口测试实践

1.安装Ant

下载地址:http://ant.apache.org/bindownload.cgi

unzip apache-ant-1.9.14-bin.zip
export ANT_HOME=/usr/local/apache-ant-1.9.14
export PATH=$PATH:$JMETER_HOME/bin:$ANT_HOME/bin
sudo cp ant-jmeter-1.1.1.jar  /usr/local/apache-ant-1.9.14/lib/
sudo cp jmeter.results.shanhe.me.xsl  /usr/local/apache-jmeter-5.1.1/extras/
sudo cp jmeter-results-detail-report_21.xsl  /usr/local/apache-jmeter-5.1.1/extras/

2.build.xml

<?xml version="1.0" encoding="utf8"?>
<!-- 拷贝报告所需的图片资源至目标目录 -->
<project name="ant-jmeter-test" default="run" basedir=".">
    <tstamp>
        <format property="time" pattern="yyyyMMddHHmm" />
    </tstamp>
    <!-- 需要改成自己本地的jmeter目录-->  
    <property name="jmeter.home" value="/usr/local/apache-jmeter-5.1.1" />
    <!-- jmeter生成的jtl格式的结果报告的路径--> 
    <property name="jmeter.result.jtl.dir" value="./result/jtlfile" />
    <!-- jmeter生成的html格式的结果报告的路径-->
    <property name="jmeter.result.html.dir" value="./result/htmlfile" />
    <!-- ʺ生成的报告的前缀-->  
    <property name="ReportName" value="TestReport_" />
    <property name="jmeter.result.jtlName" value="${jmeter.result.jtl.dir}/${ReportName}${time}.jtl" />
    <property name="jmeter.result.htmlName" value="${jmeter.result.html.dir}/${time}_SummaryReport.html" />
    <property name="jmeter.detail.result.jtlName" value="${jmeter.result.jtl.dir}/${ReportName}${time}.jtl" />
    <property name="jmeter.detail.result.htmlName" value="${jmeter.result.html.dir}/${time}_DetailReport.html" />
    <target name="run">
        <antcall target="test" />
        <antcall target="report" />
  </target>

    <target name="test">
        <taskdef name="jmeter" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask" />
        <jmeter jmeterhome="${jmeter.home}" resultlog="${jmeter.result.jtlName}">
             <!-- 声明要运行的脚本“*.jmx”指包含此目录下的所有jmeter脚本-->
            <testplans dir="./scripts" includes="*.jmx" />
           <property name="jmeter.save.saveservice.output_format" value="xml"/>

        </jmeter>
    </target>
    <path id="xslt.classpath">
            <fileset dir="${jmeter.home}/lib" includes="xalan*.jar"/>
            <fileset dir="${jmeter.home}/lib" includes="serializer*.jar"/>
    </path>

    <target name="report">
        <tstamp> 
                <format property="report.datestamp" pattern="yyyy/MM/dd HH:mm" />
        </tstamp>
        <xslt 
            classpathref="xslt.classpath"
            force="true"
            in="${jmeter.detail.result.jtlName}"
            out="${jmeter.detail.result.htmlName}"
            style="${jmeter.home}/extras/jmeter.results.shanhe.me.xsl">
            <param name="dateReport" expression="${report.datestamp}"/>
        </xslt>
        <xslt 
            classpathref="xslt.classpath"
            force="true"
            in="${jmeter.result.jtlName}"
            out="${jmeter.result.htmlName}"
            style="${jmeter.home}/extras/jmeter-results-detail-report_21.xsl">
            <param name="dateReport" expression="${report.datestamp}"/>
        </xslt>
        <!-- 拷贝报告所需的图片资源至目标目录 --> 
        <copy todir="${jmeter.result.html.dir}">
            <fileset dir="${jmeter.home}/extras">
                <include name="collapse.png" />
                <include name="expand.png" />
            </fileset>
        </copy>
    </target>
</project>

3. 运行测试

ant

Buildfile: /Users/zeyang/Desktop/jmeter-test/build.xml

run:

test:
   [jmeter] Executing test plan: /Users/zeyang/Desktop/jmeter-test/scripts/blog.jmx ==> /Users/zeyang/Desktop/jmeter-test/result/jtlfile/TestReport_201908181740.jtl
   [jmeter] 2019-08-18 17:40:49,847 main ERROR FileManager (jmeter.log) java.io.FileNotFoundException: jmeter.log (Permission denied) java.io.FileNotFoundException: jmeter.log (Permission denied)
   [jmeter]   at java.io.FileOutputStream.open0(Native Method)
   [jmeter]   at java.io.FileOutputStream.open(FileOutputStream.java:270)
   [jmeter]   at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
   [jmeter]   at org.apache.logging.log4j.core.appender.FileManager$FileManagerFactory.createManager(FileManager.java:422)
   [jmeter]   at org.apache.logging.log4j.core.appender.FileManager$FileManagerFactory.createManager(FileManager.java:406)
   [jmeter]   at org.apache.logging.log4j.core.appender.AbstractManager.getManager(AbstractManager.java:113)
   [jmeter]   at org.apache.logging.log4j.core.appender.OutputStreamManager.getManager(OutputStreamManager.java:114)
   [jmeter]   at org.apache.logging.log4j.core.appender.FileManager.getFileManager(FileManager.java:180)
   [jmeter]   at org.apache.logging.log4j.core.appender.FileAppender$Builder.build(FileAppender.java:95)
   [jmeter]   at org.apache.logging.log4j.core.appender.FileAppender$Builder.build(FileAppender.java:51)
   [jmeter]   at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:123)
   [jmeter]   at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:959)
   [jmeter]   at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:899)
   [jmeter]   at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:891)
   [jmeter]   at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:514)
   [jmeter]   at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:238)
   [jmeter]   at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:250)
   [jmeter]   at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:547)
   [jmeter]   at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:619)
   [jmeter]   at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:636)
   [jmeter]   at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:231)
   [jmeter]   at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:153)
   [jmeter]   at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
   [jmeter]   at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
   [jmeter]   at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext(AbstractLoggerAdapter.java:121)
   [jmeter]   at org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:43)
   [jmeter]   at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:46)
   [jmeter]   at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29)
   [jmeter]   at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:358)
   [jmeter]   at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)
   [jmeter]   at org.apache.jmeter.JMeter.<clinit>(JMeter.java:124)
   [jmeter]   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
   [jmeter]   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
   [jmeter]   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
   [jmeter]   at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
   [jmeter]   at org.apache.jmeter.NewDriver.main(NewDriver.java:251)
   [jmeter]

report:
     [xslt] Processing /Users/zeyang/Desktop/jmeter-test/result/jtlfile/TestReport_201908181740.jtl to /Users/zeyang/Desktop/jmeter-test/result/htmlfile/201908181740_DetailReport.html
     [xslt] Loading stylesheet /usr/local/apache-jmeter-5.1.1/extras/jmeter.results.shanhe.me.xsl
     [xslt] Processing /Users/zeyang/Desktop/jmeter-test/result/jtlfile/TestReport_201908181740.jtl to /Users/zeyang/Desktop/jmeter-test/result/htmlfile/201908181740_SummaryReport.html
     [xslt] Loading stylesheet /usr/local/apache-jmeter-5.1.1/extras/jmeter-results-detail-report_21.xsl
     [copy] Copying 2 files to /Users/zeyang/Desktop/jmeter-test/result/htmlfile

BUILD SUCCESSFUL
Total time: 5 seconds

4.测试报告

本文分享自微信公众号 - DevOps持续集成(devopsadmin)

原文出处及转载信息见文内详细说明,如有侵权,请联系 yunjia_community@tencent.com 删除。

原始发表时间:2019-08-18

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • Mac下配置免安装的tomcat

    在jdk安装好的情况下我们只需要在终端运行我下好的压缩包中的starup.sh文件就能正常运行tomcat服务器了 在终端运行shutdown.sh文件就能...

    用户4478423
  • Nginx怎么实现https?Nginx 安装 SSL 配置 HTTPS 超详细完整全过程

    文章来源:Nginx怎么实现https?Nginx 安装 SSL 配置 HTTPS 超详细完整全过程

    尊托云数
  • 源码分析 RocketMQ DLedger(多副本) 之日志复制-下篇

    从上文得知,主节点会主动向从节点传播日志,从节点会通过网络接受到请求数据进行处理,其调用链如图所示:

    丁威
  • 使用 Apache 搭建 VPC 服务器代理

    本文使用「署名 4.0 国际 (CC BY 4.0)」许可协议,欢迎转载、或重新修改使用,但需要注明来源。 署名 4.0 国际 (CC BY 4.0)

    soulteary
  • 天天在用消息队列,却不知道为啥要用 MQ ,这就尴尬了

    一个用消息队列的人,不知道为啥用,有点尴尬。没有复习这点,很容易被问蒙,然后就开始胡扯了。

    芋道源码
  • Cassandra原理 | Apache Cassandra简介

    Apache Cassandra 是一个开源的、分布式、无中心、弹性可扩展、高可用、容错、一致性可调、面向行的数据库,它基于 Amazon Dynamo 的分布...

    王知无
  • ASP.NET Core 3.0 使用gRPC

    gRPC 是一个由Google开源的,跨语言的,高性能的远程过程调用(RPC)框架。 gRPC使客户端和服务端应用程序可以透明地进行通信,并简化了连接系统的构建...

    梁规晓
  • 轻拢慢捻,微服务熔断大总管

    我这篇文章来的晚了些,因为hystrix已经进入维护模式。但已经有非常多的同学入坑了,那么本篇文章就是及时雨。本文将说明熔断使用的一些注意事项,可能会细的让你厌...

    xjjdog
  • 性能测试技能树

    基础: 完整的性能测试流程     需求-计划-方案-环境搭建-用例设计-数据准备-场景设计-脚本开发-脚本执行-结果分析-问题反馈-性能调...

    飞天小子
  • 《微服务设计》第 8 章 监控

    yeedomliu

扫码关注云+社区

领取腾讯云代金券