Jmeter 类型化变量声明:方法调用

Jmeter Typed variable declaration : Method Invocation

我在使用 Jmeter BeanShell 预处理器时遇到问题。 脚本调用我将它们放在目录 "D:\Software\apache-jmeter-3.0\lib\ext" 下的 jar。 enter image description here

这是我的 BeanShell 代码:

import com.evergrande.api.test.JsonClientUtil;
import com.evergrande.common.utils.JsonUtil;
import com.fasterxml.jackson.databind.node.ObjectNode;

JsonClientUtil jcu=new JsonClientUtil();
ObjectNode node = JsonUtil.createObjectNode();//when I try to use the method in JsonUtil(Class),it came out error

错误:

2016/09/24 22:48:06 ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval   Sourced file: inline evaluation of: ``import com.evergrande.api.test.JsonClientUtil; import com.evergrande.common.util . . . '' : Typed variable declaration : Method Invocation JsonUtil.createObjectNode 
2016/09/24 22:48:06 WARN  - jmeter.modifiers.BeanShellPreProcessor: Problem in BeanShell script org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval    Sourced file: inline evaluation of: ``import com.evergrande.api.test.JsonClientUtil; import com.evergrande.common.util . . . '' : Typed variable declaration : Method Invocation JsonUtil.createObjectNode 

我可以在我的 java 代码中调用 "createObjectNode" 方法。 那么,我该如何解决这个问题呢?谢谢大家

  1. 不要将任何 jar 文件放入 lib/ext 文件夹,它应该仅用于 JMeter 核心组件和插件。将您的 .jar 库放到其他地方的 "lib" 文件夹中,它们只需要在 JMeter's Claspath. Alternative option is using Add directory or jar to classpath option on Test Plan 级别

  2. 需要重新启动 JMeter 才能拾取 jars。
  3. 您可以通过使用 try/catch 块包围您的代码来获得更易读的 Beanshell 错误消息,例如

    import com.evergrande.api.test.JsonClientUtil;
    import com.evergrande.common.utils.JsonUtil;
    import com.fasterxml.jackson.databind.node.ObjectNode;
    
    try {
        JsonClientUtil jcu=new JsonClientUtil();
        ObjectNode node = JsonUtil.createObjectNode();
    }
    catch (Throwable ex) {
        log.error("Beanshell failure: ", ex);
        throw ex;
    }
    

    因此,如果您的脚本失败,您将能够在 jmeter.log 文件中查看堆栈跟踪详细信息。另一种深入了解 Beanshell 脚本失败的方法是添加 debug(); command to the beginning of your script. It will trigger verbose output to the console. Check out How to Debug your Apache JMeter Script 文章以获取有关 JMeter 调试技术的更多信息。