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

作的事情:數據庫

在接口自動化迴歸測試加入封裝好的jemter api作接口性能測試,完成測試數據記錄
輸出測試報告和數據庫中,造成迭代版本性能走勢趨勢,找出新增功能在迭代中性能的表現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可獲得數據(性能數據源):ide

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,寫入性能數據):測試

相關文章
相關標籤/搜索