jmeter 使用BeanShell 进行运算 并且进行断言

1.导入jar包的方法

因为运算需要用到jar包 所以先进行导入
jmeter目录下创建一个dependencies目录 里面放置需要导入的jar包
在这里插入图片描述
修改JMETER配置文件jmeter.properties 该文件在jmeter\bin\目录里
路径修改为 plugin_dependency_paths=…/dependencies;在这里插入图片描述
至此打开jmeter就可以直接导入jar包

提取接口参数 并且进行运算

提取接口参数 并且把要用的参数定义到用户参数 如图
在这里插入图片描述
提成金额计算公式

//BeanShell 取样器
import org.apache.log4j.Logger;

source("C:\\Users\\dell\\Desktop\\Huisheng_ERP_Port_Project\\jmeter\\test\\data\\Myclass.java"); //调用java文件
totalPrice = vars.get("totalPrice");
totalSellPrice = vars.get("totalSellPrice");
rebatePrice = vars.get("rebatePrice");
taxPrice = vars.get("taxPrice");
freightPrice = vars.get("freightPrice");
accountExpensePrice = vars.get("accountExpensePrice");
dapRate = vars.get("dapRate");
travelExpensePrice = vars.get("travelExpensePrice");
deductsAPercentagePrice= vars.get("deductsAPercentagePrice");
deductsAPercentagePrice1= vars.get("deductsAPercentagePrice1");
vars.put("totalDap",deductsAPercentagePrice.toString());
b = new Myclass().j(deductsAPercentagePrice.toString());  //调用文件类
res =new Myclass().a(totalPrice,totalSellPrice,rebatePrice,dapRate,freightPrice,travelExpensePrice,accountExpensePrice,b);
vars.put("add",res);
//log.info(res);
//log.info(deductsAPercentagePrice1);
//BeanShell 断言
import org.apache.log4j.Logger;
import java.math.BigDecimal;
import java.math.RoundingMode;

res = vars.get("add");

a = new BigDecimal(res).setScale(2,RoundingMode.HALF_UP).toString();  //保留两位小数
log.info(a);
deductsAPercentagePrice2= vars.get("deductsAPercentagePrice1");
//log.info(res);
log.info(deductsAPercentagePrice2);
if (deductsAPercentagePrice2.equals(a)){
	Failure = false ;
	 log.info("成功");
	}
else{
	Failure=true ;
	log.info("失败");
	}
//java文件
class Myclass {

	//运算公式(totalPrice-totalSellPrice-rebatePrice-(totalPrice/(1+dapRate)*dapRate})-freightPrice-travelExpensePrice-accountExpensePrice)* 计算销售阶梯 +(totalSellPrice*1%)
	// taxPrice = totalPrice/(1+dapRate)*dapRate
    public String a(String totalPrice, String totalSellPrice, String rebatePrice,
                    String dapRate, String freightPrice, String travelExpensePrice, String accountExpensePrice, String j) {
                       
        double t = Double.valueOf(dapRate) / 100;
        double taxPrice = Double.valueOf(totalPrice) / (1 + t) * t;
        double l = Double.valueOf(totalPrice) - Double.valueOf(totalSellPrice) 
                    - Double.valueOf(rebatePrice) - Double.valueOf(taxPrice) 
                    - Double.valueOf(freightPrice) - Double.valueOf(travelExpensePrice) 
                    - Double.valueOf(accountExpensePrice);
        double result = l * Double.valueOf(j) + (Double.valueOf(totalSellPrice) * 0.01);
        return String.valueOf(result);
    }

	//判断销售阶梯计算提成百分比
    public String j(String total){
        String[] t1 = total.split(",");
        double t = 0d;
        for(int i =0;i< t1.length;i++){
            t += Double.valueOf(t1[i]);
        }
        double rate = 10d;
        //Double t = Double.valueOf(total);
        if (t > 1000000 && t < 2000000) {
            rate = 15d;
        }
        if (t > 2000000 && t < 3000000) {
            rate = 20d;
        }
        if (t > 3000000) {
            rate = 30d;
        }
       return String.valueOf(rate / 100);

    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值