带有Maven的Jmeter以及使用Groovy导入使用外部Groovy脚本的问题 [英] Jmeter with maven and using external groovy scripts issues with groovy imports

查看:209
本文介绍了带有Maven的Jmeter以及使用Groovy导入使用外部Groovy脚本的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用groovy脚本从maven执行jmeter测试,但是出现以下错误.对于设置jmeter和maven,我做了此处所述的操作.

I'd like to execute jmeter tests from maven using groovy scripts, but I got the error below. For setting up jmeter and maven I did what is described here.

我应该将groovy函数和实体打包到jar中并复制到jmeter的lib目录中,仅将那些groovy脚本放在包含采样器代码的jmx文件旁边吗?

Shall I package my groovy functions and entities into a jar and copy into jmeter's lib directory and only put those groovy scripts next to the jmx file which contains the sampler code?

2019-06-22 17:40:17,714 INFO o.a.j.s.SampleResult: sampleresult.useNanoTime=true
2019-06-22 17:40:17,714 INFO o.a.j.s.SampleResult: sampleresult.nanoThreadSleep=5000
2019-06-22 17:40:17,744 ERROR o.a.j.p.j.s.JSR223Sampler: Problem in JSR223 script CreateUsers, message: javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script4.groovy: 4: unable to resolve class com.google.gson.Gson
 @ line 4, column 1.
   import com.google.gson.Gson;
   ^

推荐答案

我找到了答案:

  • 我需要将要在测试中使用的库打包到jar中,然后将其放入jmeter/lib目录
  • 我必须对齐Sampler脚本路径,以便jmeter可以使用它们

第一个解决方案是

The solution for the first is the following from jmeter-maven-plugin doc:

<project>
    [...]
        <build>
            <plugins>
                <plugin>
                    <groupId>com.lazerycode.jmeter</groupId>
                    <artifactId>jmeter-maven-plugin</artifactId>
                    <version>USE LAST VERSION</version>
                    <executions>
                        <execution>
                            <id>jmeter-tests</id>
                            <goals>
                                <goal>jmeter</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <testPlanLibraries>
                             <artifact>org.apache.activemq:activemq-spring:5.15.2</artifact>
                 <artifact>org.apache.activemq:activemq-client:5.15.2</artifact>
                 <artifact>org.apache.activemq:activemq-broker:5.15.2</artifact>
                </testPlanLibraries>
                        <excludedArtifacts>
                             <exclusion>com.sun.jdmk:jmxtools</exclusion>
                             <exclusion>com.sun.jmx:jmxri</exclusion>
            </excludedArtifacts>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    [...]
</project>

第二个解决方案是,我需要复制jmx文件旁边的Sampler脚本. Maven可以使用 maven-resource-plugin 轻松地做到这一点.

The solution for the second is that I need to copy Sampler scripts next to jmx file. Maven can do this easily using maven-resource-plugin.

这篇关于带有Maven的Jmeter以及使用Groovy导入使用外部Groovy脚本的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆