您的位置:首页 > 编程语言 > Java开发

loadrunner接口性能测试分享

2017-10-16 16:24 459 查看
最近做了一次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("+++++++++++++++++++++++++++++++++
4000
+++++++++");
}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息