Jmeter's BeanShell takes out the parameters and performs four arithmetic operations, and judges whether it is correct

  1. First call the balance interface, use the regular method to extract the balance field in the response, and record it as the variable acctBal1
  2. make a payment transaction
  3. Call the balance interface again, use the regular method to extract the balance field in the response, and record it as the variable acctBal2
  4. Finally, you can see the assertion error information in the result tree, and there is no prompt when the assertion is correct
  5. The following is the beanshell assertion script
//调用BigDecimal
import java.text.DecimalFormat;
import java.math.BigDecimal;
//查询交易前账户余额
String Preamount = vars.get("acctBal1");
log.info("交易前账户余额------"+Preamount);
//查询交易前账户余额
String Postamount = vars.get("acctBal2");
log.info("交易后账户余额-----"+Postamount);
//用交易后余额减交易前余额乘0.01换算小数位,并计算出差额
String difference = String.valueOf(Double.parseDouble(Postamount)*Double.parseDouble("0.01")-Double.parseDouble(Preamount)*Double.parseDouble("0.01"));
log.info("差额-----"+difference);
//判断差额等于20
if (difference.equals("20.0")){
    
    
	log.info(difference);
	return;
	
}else{
    
    
	log.info(difference);
	Failure = true;
	FailureMessage = "差额计算不正确";}

Guess you like

Origin blog.csdn.net/zhuan_long/article/details/132162051