• 接口自动化中的性能(jemter api)


    做的事情:

    在接口自动化回归测试加入封装好的jemter api做接口性能测试,完成测试数据记录
    输出测试报告和数据库中,形成迭代版本性能走势趋势,找出新增功能在迭代中性能的表现


    注意点:
    由于是每日构建,性能测试时也要保持机器的硬件和网络的稳定性。
    如果每次测试机器不一样那么性能数据受环境影响较大,无法直接看出是不是更新代码导致的。

    Jmeter api
    <dependency>
    <groupId>kg.apc</groupId>
    <artifactId>jmeter-plugins</artifactId>
    <version>1.0.0</version>
    </dependency>

    部分主要设置

            // Engine
            StandardJMeterEngine jm = new StandardJMeterEngine();
            // jmeter.properties
            JMeterUtils.loadJMeterProperties("D://jmeter//bin//jmeter.properties");
            JMeterUtils.setJMeterHome("D://jmeter");
            JMeterUtils.setLocale(new Locale("ignoreResources"));
            // HTTP Sampler 接口信息
            HTTPSampler httpSampler = new HTTPSampler();
            httpSampler.setName("TestCodeproject");
            httpSampler.setDomain("test.test.cn");
            httpSampler.setPort(80);
            httpSampler.setProtocol("http");
            httpSampler.setMethod("GET");
            httpSampler.setPath("/"// Thread Group
            ThreadGroup threadGroup = new ThreadGroup();
            threadGroup.setName("Test");
            threadGroup.setNumThreads(2000);  //2000并发     
            //数据源
            MyResultCollector requestCollector = new MyResultCollector();

    ResultCollector可得到数据(性能数据源):

    public class MyResultCollector extends ResultCollector {
      @Override
        public void sampleOccurred(SampleEvent e) {
            super.sampleOccurred(e);
            SampleResult r = e.getResult();
            String threadGroupName= e.getThreadGroup();
            System.out.println(threadGroupName);
    
            System.out.println(r.getEndTime() +"  getEndTime");
            System.out.println(r.getStartTime() +"  getStartTime");
            System.out.println(r.getErrorCount() +"  getErrorCount");
            System.out.println(r.getIdleTime() +"  getIdleTime");
            System.out.println(r.getLatency() +"  getLatency");
            System.out.println(r.getTime() +"  getTime");
            System.out.println(r.getTimeStamp() +"  getTimeStamp");
            System.out.println(r.getSubResults() +"  getSubResults");
            System.out.println(Arrays.toString(r.getSubResults()) +"  getSubResults");
    }


    分析计算得出log数据:

    ------------------
    MULE TotalTime0.647
    MULE ExpectedThreads 1
    MULE StartedThreads 2000
    MULE StoppedThreads 2000
    MULE Requests 2000
    MULE Throughput 3092.7357032457494
    MULE BytesPerSecond 238.59218025502318 KB
    MULE BytesPerRequestAvg 78.99750124937532 B
    MULE Error% 0.0
    MULE AvgLatency 32.093453273363316
    MULE MinLatency 21
    MULE 50thPercentile 25
    MULE 90thPercentile 39
    MULE 95thPercentile 108
    MULE 99thPercentile 141
    MULE MaxLatency 165
    ------------------
    DEBUG   2018-01-15 11:17:58.677 [jmeter.r] (): Closing: d://file.jtl
    INFO    2018-01-15 11:17:59.365 [jmeter.r] (): summary =   2001 in     2s = 1298.5/s Avg:    32 Min:    21 Max:   165 Err:     0 (0.00%)
    summary =   2001 in     2s = 1298.5/s Avg:    32 Min:    21 Max:   165 Err:     0 (0.00%)

    写入接口自动化report(二次扩展zreport,写入性能数据):

  • 相关阅读:
    合并多个文件夹里的内容到一起
    查看电脑的计算机名、IP和物理地址
    代码重新生成的问题与解决办法
    ElasticSearch7.3学习(二十二)Text字段排序、Scroll分批查询场景解析
    docker 安装与使用(win10)
    Windows下文件夹映射的实现(将文件夹从一个盘映射到另一个盘)
    SVN 改变文件名的大小写,提交后自动撤销更改
    eslint使用规则+Vscode设置
    mysql杂记使用FEDERATED汇总数据
    jeecgbootvue3学习交流
  • 原文地址:https://www.cnblogs.com/season-xie/p/8284841.html
Copyright © 2020-2023  润新知