loadrunner接口性能测试分享

来源:互联网 发布:mac mini性能怎么样 编辑:程序博客网 时间:2024/06/05 14:30

最近做了一次java脚本的lr性能测试
不过后来直接用eclipse进行了一次模拟,感觉也不错
先说lr
这里写图片描述

选择JavaVuser
之后 会生成脚本如下:

 */import lrapi.lr;public class Actions{    public int init() throws Throwable {        return 0;    }//end of init    public int action() throws Throwable {        return 0;    }//end of action    public int end() throws Throwable {        return 0;    }//end of end}

在你的脚本中增加

 */import lrapi.lr;public class Actions{    public int init() throws Throwable {        return 0;    }//end of init    public 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 action    public 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 block                    e.printStackTrace();                }//              System.out.println(Thread.currentThread().getName()+"||当前线程执行次数:"+i+"||耗时为:||"+excTime+"||TPS=||"+ThreadTest.tps+"||执行结果:"+test.flag);                System.out.println("++++++++++++++++++++++++++++++++++++++++++");             }        }}
阅读全文
0 0
原创粉丝点击