我创建了一个JMeter测试文件,它运行我用java编写的一些测试
当我在JMeter中运行文件时,它们运行正常并且测试通过。现在我已经配置了maven来运行JMX文件,当我运行验证目标时,它会执行JMX文件。但是现在它失败并显示以下错误消息:
JMeter.jmx.log:“jmeter.protocol.java.sampler.JUnitSampler:ClassNotFoundException :: com.mynamespace.tests.product.ProductTest”
Jmeter.jtl:“无法创建com.mynamespace.tests.product.ProductTest的实例,原因可能是缺少空构造函数和一个String构造函数或者无法实例化构造函数,请检查jmeter日志文件中的警告消息”
为了让JMeter知道这个类,我构建了一个jar并将其复制到Jmeter的lib目录中。运行jmeter maven插件时是否需要做类似的事情? - 当运行验证目标时,它应该能够在项目构建时看到Class。
添加到pom.xml:
<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>
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>
答案 0 :(得分:2)
您需要修改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>
参考文献: