我想使用JMeter Maven插件运行性能测试的JMeter测试。我正在目标文件夹中创建我的项目快照jar。这个快照jar包含使用maven-assembly-plugin的测试类和外部jar。相同的快照jar能够从JUnit应用程序中检测到JMeter测试方法并成功运行,但当我将其放入<project>/src/test/jmeter/lib/junit中时,无法从插件中检测到相同的测试方法。
我把JMX文件放在<project>/src/test/jmeter中,快照jar放在这个文件夹<project>/src/test/jmeter/lib/junit中。
请在下面找到我的pom文件。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com</groupId>
<artifactId>myproject</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>3.4.0</version>
<executions>
<!-- Generate JMeter configuration -->
<execution>
<id>configuration</id>
<goals>
<goal>configure</goal>
</goals>
</execution>
<!-- Run JMeter tests -->
<execution>
<id>jmeter-tests</id>
<goals>
<goal>jmeter</goal>
</goals>
</execution>
<!-- Fail build on errors in test -->
<execution>
<id>jmeter-check-results</id>
<goals>
<goal>results</goal>
</goals>
</execution>
</executions>
<configuration>
<generateReports>true</generateReports>
<jmeterExtensions>
<artifact>kg.apc:jmeter-plugins:pom:1.4.0</artifact>
<artifact>kg.apc:jmeter-plugins-json:2.7</artifact>
</jmeterExtensions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
<archive>
<manifest>
<mainClass>MainClass.TestMethod</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>maven-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</project>我能够从JMeter应用程序中运行相同的测试,但是不能从mvn clean verify命令中检测到相同的类?
运行mvn clean verify后生成的日志如下。上面写着JUnitSampler: ClassNotFoundException:: MyClass.TestMethod
2021-07-12 11:18:38,748 WARN o.a.j.p.j.s.JUnitSampler: ClassNotFoundException:: MyClass.TestMethod
2021-07-12 11:18:38,750 INFO o.a.j.s.SampleResult: Note: Sample TimeStamps are START times
2021-07-12 11:18:38,750 INFO o.a.j.s.SampleResult: sampleresult.default.encoding is set to ISO-8859-1
2021-07-12 11:18:38,750 INFO o.a.j.s.SampleResult: sampleresult.useNanoTime=true
2021-07-12 11:18:38,750 INFO o.a.j.s.SampleResult: sampleresult.nanoThreadSleep=5000
2021-07-12 11:18:38,751 INFO o.a.j.t.JMeterThread: Thread is done: ThreadGroup 1-1
2021-07-12 11:18:38,751 INFO o.a.j.t.JMeterThread: Thread finished: ThreadGroup 1-1
2021-07-12 11:18:40,745 INFO o.a.j.t.JMeterThread: Thread started: ThreadGroup 1-2
2021-07-12 11:18:40,745 WARN o.a.j.p.j.s.JUnitSampler: ClassNotFoundException:: MyClass.TestMethod
2021-07-12 11:18:40,746 INFO o.a.j.t.JMeterThread: Thread is done: ThreadGroup 1-2
2021-07-12 11:18:40,746 INFO o.a.j.t.JMeterThread: Thread finished: ThreadGroup 1-2
2021-07-12 11:18:42,746 INFO o.a.j.t.JMeterThread: Thread started: ThreadGroup 1-3
2021-07-12 11:18:42,746 WARN o.a.j.p.j.s.JUnitSampler: ClassNotFoundException:: MyClass.TestMethod
2021-07-12 11:18:42,746 INFO o.a.j.t.JMeterThread: Thread is done: ThreadGroup 1-3
2021-07-12 11:18:42,747 INFO o.a.j.t.JMeterThread: Thread finished: ThreadGroup 1-3
2021-07-12 11:18:44,748 INFO o.a.j.t.JMeterThread: Thread started: ThreadGroup 1-4
2021-07-12 11:18:44,749 WARN o.a.j.p.j.s.JUnitSampler: ClassNotFoundException:: MyClass.TestMethod发布于 2021-07-13 06:13:36
我认为您需要在自定义本地Maven存储库测试中添加指向.jar文件的JUnit:
<repositories>
<repository>
<id>your-junit-jar</id>
<name>your junit repo</name>
<url>file:/path/to/your-junit-jar-with-dependencies.jar</url>
</repository>
</repositories>然后,您应该能够使用标签使JMeter知道包含JUnit测试的额外库,如下所示:
<junitLibraries>
<artifact>com.yourcompany.yourgroup:your-artifact:1.0-SNAPSHOT</artifact>
</junitLibraries>更多信息:如何使用JMeter Maven插件
https://stackoverflow.com/questions/68351135
复制相似问题