Java 在Maven中运行时,JMeter失败,ClassNotFoundException
我创建了一个JMeter测试文件,它运行我用java编写的一些测试 当我在JMeter中运行文件时,它们运行良好,测试通过。现在,我已经将maven配置为运行JMX文件,当我运行verify目标时,它将执行JMX文件。但是,现在它失败了,并显示以下错误消息: JMeter.jmx.log:“JMeter.protocol.java.sampler.JUnitSampler:ClassNotFoundException::com.mynamespace.tests.product.ProductTest” Jmeter.jtl:“未能创建com.mynamespace.tests.product.ProductTest的实例,原因可能是缺少空构造函数和一个字符串构造函数,或者未能实例化构造函数,请检查Jmeter日志文件中的警告消息” 为了让JMeter知道这个类,我构建了一个jar并将其复制到JMeter的lib目录。运行jmeter maven插件时是否需要执行类似的操作当然,在运行verify目标时,它应该能够在构建项目时看到类 添加到pom.xml:Java 在Maven中运行时,JMeter失败,ClassNotFoundException,java,maven,classnotfoundexception,jmeter-maven-plugin,Java,Maven,Classnotfoundexception,Jmeter Maven Plugin,我创建了一个JMeter测试文件,它运行我用java编写的一些测试 当我在JMeter中运行文件时,它们运行良好,测试通过。现在,我已经将maven配置为运行JMX文件,当我运行verify目标时,它将执行JMX文件。但是,现在它失败了,并显示以下错误消息: JMeter.jmx.log:“JMeter.protocol.java.sampler.JUnitSampler:ClassNotFoundException::com.mynamespace.tests.product.ProductT
<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>1.9.1</version>
<executions>
<execution>
<id>jmeter-tests</id>
<phase>verify</phase>
<goals>
<goal>jmeter</goal>
</goals>
</execution>
</executions>
</plugin>
com.lazerycode.jmeter
jmetermaven插件
1.9.1
jmeter测试
验证
性能测试
Jmeter.jmx:
<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="2.6" jmeter="2.11 r1554548">
<hashTree>
<TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test Plan" enabled="true">
<stringProp name="TestPlan.comments"></stringProp>
<boolProp name="TestPlan.functional_mode">false</boolProp>
<boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
<elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
<collectionProp name="Arguments.arguments"/>
</elementProp>
<stringProp name="TestPlan.user_define_classpath"></stringProp>
</TestPlan>
<hashTree>
<ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Thread Group" enabled="true">
<stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
<elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true">
<boolProp name="LoopController.continue_forever">false</boolProp>
<stringProp name="LoopController.loops">1</stringProp>
</elementProp>
<stringProp name="ThreadGroup.num_threads">1</stringProp>
<stringProp name="ThreadGroup.ramp_time">1</stringProp>
<longProp name="ThreadGroup.start_time">1408690229000</longProp>
<longProp name="ThreadGroup.end_time">1408690229000</longProp>
<boolProp name="ThreadGroup.scheduler">false</boolProp>
<stringProp name="ThreadGroup.duration"></stringProp>
<stringProp name="ThreadGroup.delay"></stringProp>
</ThreadGroup>
<hashTree>
<JUnitSampler guiclass="JUnitTestSamplerGui" testclass="JUnitSampler" testname="JUnit Request" enabled="true">
<stringProp name="junitSampler.classname">com.mynamespace.tests.product.ProductTest</stringProp>
<stringProp name="junitsampler.constructorstring"></stringProp>
<stringProp name="junitsampler.method">saveProduct</stringProp>
<stringProp name="junitsampler.pkg.filter"></stringProp>
<stringProp name="junitsampler.success">Test successful</stringProp>
<stringProp name="junitsampler.success.code">1000</stringProp>
<stringProp name="junitsampler.failure">Test failed</stringProp>
<stringProp name="junitsampler.failure.code">0001</stringProp>
<stringProp name="junitsampler.error">An unexpected error occured</stringProp>
<stringProp name="junitsampler.error.code">9999</stringProp>
<stringProp name="junitsampler.exec.setup">false</stringProp>
<stringProp name="junitsampler.append.error">true</stringProp>
<stringProp name="junitsampler.append.exception">true</stringProp>
<boolProp name="junitsampler.junit4">true</boolProp>
</JUnitSampler>
<hashTree/>
<JUnitSampler guiclass="JUnitTestSamplerGui" testclass="JUnitSampler" testname="JUnit Request" enabled="true">
<stringProp name="junitSampler.classname">com.mynamespace.tests.product.ProductTest</stringProp>
<stringProp name="junitsampler.constructorstring"></stringProp>
<stringProp name="junitsampler.method">getProduct</stringProp>
<stringProp name="junitsampler.pkg.filter"></stringProp>
<stringProp name="junitsampler.success">Test successful</stringProp>
<stringProp name="junitsampler.success.code">1000</stringProp>
<stringProp name="junitsampler.failure">Test failed</stringProp>
<stringProp name="junitsampler.failure.code">0001</stringProp>
<stringProp name="junitsampler.error">An unexpected error occured</stringProp>
<stringProp name="junitsampler.error.code">9999</stringProp>
<stringProp name="junitsampler.exec.setup">false</stringProp>
<stringProp name="junitsampler.append.error">true</stringProp>
<stringProp name="junitsampler.append.exception">true</stringProp>
<boolProp name="junitsampler.junit4">true</boolProp>
</JUnitSampler>
<hashTree/>
</hashTree>
</hashTree>
</hashTree>
</jmeterTestPlan>
假的
假的
持续
假的
1.
1.
1.
1408690229000
1408690229000
假的
com.mynamespace.tests.product.ProductTest
储蓄品
测试成功
1000
测试失败
0001
发生意外错误
9999
假的
真的
真的
真的
com.mynamespace.tests.product.ProductTest
getProduct
测试成功
1000
测试失败
0001
发生意外错误
9999
假的
真的
真的
真的
您需要修改pom.xml
文件,以将jar工件作为依赖项包含在内。比如:
<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>1.10.0</version>
<executions>
<execution>
<phase>verify</phase>
<id>jmeter-tests</id>
<goals>
<goal>jmeter</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.mynamespace.tests.product</groupId>
<artifactId>com.mynamespace.tests.product.ProductTest</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>
com.lazerycode.jmeter