接口自动化中的性能(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,写入性能数据):

 

转载于:https://www.cnblogs.com/season-xie/p/8284841.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值