jmeter beashell调用java文件/class文件/jar包方法

上一篇 / 下一篇  2022-04-16 11:55:53 / 天气: 晴朗 / 心情: 高兴 / 个人分类:Jmeter

前提:
elipse中的java建立一个项目,项目结构包括: 包名:com.test, 其中有一个java文件 beanShellPractice.java,  java文件中有一个方法:calSquare

代码如下:
package com.test;
public class beanShellPractice {
public  int calSquare(int i) {
int b;
b = i * i;
return b;
}
public static void main(String[] args) {
beanShellPractice beanShellPractice = new beanShellPractice();
        System.out.println(beanShellPractice.calSquare(20));
       }
}


1. jmeter中如何调用jar包
   1)elipse中打包,下一步,下一步即可。
   2)jmeter test plan首页,指定此jar的位置
   3)beanshell中的代码如下:
   import com.test.*;--- 引包,下面操作和java中调用某个方法完全一致

int x;
String y;
beanShellPractice beanShellPractice = new beanShellPractice();
x = beanShellPractice.calSquare(12);
y = String.valueOf(x);
System.out.println(y);
log.info("y="+y);

2. jmeter中如何调用java文件
    只需要将调用jar包中的第一行,import com.test.* 替换为   source("C:/Mywork/100_ScrpitDev/EclipseWorkSpace/beanShell/src/com/test/beanShellPractice.java");  用于指定java文件的位置

   其他后续代码, 和调用jar包的完全相同

3. jmeter中如何调用class文件
   在调用jar包方法中的第一行前面,再添加一行,addClassPath("C:/Mywork/100_ScrpitDev/EclipseWorkSpace/beanShell/bin/com/test/beanShellPractice.class");  用于指定class文件的位置,

   其他后续代码, 和调用jar包的完全相同
 



TAG: Beanshell beanshell Jmeter jmeter

 

评分:0

我来说两句

Open Toolbar