loadrunner接口性能测试分享
生活随笔
收集整理的這篇文章主要介紹了
loadrunner接口性能测试分享
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
最近做了一次java腳本的lr性能測試
不過后來直接用eclipse進行了一次模擬,感覺也不錯
先說lr
選擇JavaVuser
之后 會生成腳本如下:
在你的腳本中增加
*/import lrapi.lr;public class Actions {public int init() throws Throwable {return 0;}//end of initpublic int action() throws Throwable {lr.start_transaction("b2b"); //增加數據 統計//在這里增加你的代碼即可//增加判斷邏輯 if(!(responseString ==null)&&responseString.contains("recharge failed")){lr.end_transaction("b2b", lr.PASS);}else{lr.end_transaction("b2b", lr.FAIL);}return 0;}//end of actionpublic int end() throws Throwable {return 0;}//end of end }在這里增加你的jar即可
根據tps公式,用eclipse模擬如下:
public class ThreadTest {public static int threadCount=20;//啟動線程數量public static int threadExcuteCount=1000000;//每個線程執行任務次數,沒有數量的時候設置為999999999默認無窮大public static int average; //每個任務執行的平均耗時public static float tps; //瞬時tps public static int allhits=threadCount*threadExcuteCount; //總執行任務數量public static void main(String[] args) {for (int i = 0; i <threadCount; i++) {Thread th= new Thread(new Runnable1());th.setName("測試線程"+i);th.start();}} } class Runnable1 implements Runnable{public void run() {for (int i = 0; i < 1000; i++) {long startTime=System.currentTimeMillis();//記錄開始時間 // CbApplyPayShortcut_DEBITCARD test = new CbApplyPayShortcut_DEBITCARD(); // test.main(null);cbPreAuthDirect test = new cbPreAuthDirect();try {test.main(null);} catch (Exception e) {// TODO: handle exception}System.out.println("");long endTime=System.currentTimeMillis();//記錄結束時間float excTime=(float)(endTime-startTime);ThreadTest.tps=(float)ThreadTest.threadCount*(1000/excTime);try {Thread.sleep(200000);} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();} // System.out.println(Thread.currentThread().getName()+"||當前線程執行次數:"+i+"||耗時為:||"+excTime+"||TPS=||"+ThreadTest.tps+"||執行結果:"+test.flag);System.out.println("++++++++++++++++++++++++++++++++++++++++++");}}}總結
以上是生活随笔為你收集整理的loadrunner接口性能测试分享的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何用极致业务基础平台做一个通用企业ER
- 下一篇: 病症:arm启动后应用程序界面显示…