Jmeter with maven and using external groovy scripts issues with groovy imports

限于喜欢 提交于 2019-12-11 16:02:00

问题


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.

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;
   ^

回答1:


You need to add to your pom.xml Gson dependency

<dependency>
<groupId>com.google</groupId>
<artifactId>gson</artifactId>
<version>2.1.0</version>
</dependency>



回答2:


I found the answer:

  • I need to package into jars my libraries I'd like to use in testing and put them into jmeter/lib directory
  • I have to align Sampler scripts path, so jmeter can work with them

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>

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.



来源:https://stackoverflow.com/questions/56717085/jmeter-with-maven-and-using-external-groovy-scripts-issues-with-groovy-imports

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!