我想使用groovy脚本从maven执行jmeter测试,但是出现以下错误。为了设置jmeter和maven,我做了here所述的事情。
我应该将groovy函数和实体打包到jar中并复制到jmeter的lib目录中,仅将那些groovy脚本放在包含采样器代码的jmx文件旁边吗?
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;
^
答案 0 :(得分:0)
您需要添加到pom.xml Gson dependency
<dependency> <groupId>com.google</groupId> <artifactId>gson</artifactId> <version>2.1.0</version> </dependency>
答案 1 :(得分:0)
我找到了答案:
jmeter/lib
目录中第一个解决方案是jmeter-maven-plugin文档中的以下内容:
<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文件旁边。 Maven可以使用maven-resource-plugin轻松地做到这一点。