来自:http://www.51testing.com/html/97/13997-214307.html
参考
http://code.google.com/p/jmeter-maven-plugin/wiki/HOWTOUsePlugin。
从如上url下载maven plugin及depenent。先按原文细致执行。
如上命令是把jar部署到本地maven reposity库。我个人机器repo dir为:"C:\Documents and Settings\jianzhao.liangjz\.m2\repository"
命令行实际执行如下:
mvn deploy:deploy-file -DgroupId=org.apache.jmeter -DartifactId=jmeter -Dversion=2.3 -Dpackaging=jar -Dfile=jmeter-2.3.jar -DpomFile=jmeter-2.3.pom -Durl=file://"C:\Documents and Settings\jianzhao.liangjz\.m2\repository"
按原文配置后,对maven工程实施 Mvn clean install出现多个错误,控制台上错误提示可能误导人。
在工程目录: target/jmeter/jmeter.log提供真正价值的异常信息。如:
jmeter.save.SaveService: Conversion error com.thoughtworks.xstream.converters.ConversionException: org/apache/commons/logging/LogFactory : org/apache/commons/logging/LogFactory。
源代码可参考:http://jmeter-maven-plugin.googlecode.com/svn/trunk/src/main/java/org/apache/jmeter/JMeterMojo.java
调整细节如下:
1.0 前提部署好maven/jmeter环境
D:\src\netty_websocket>mvn -version
Apache Maven 2.2.1 (r801777; 2009-08-07 03:16:01+0800)
Java version: 1.6.0_11
Java home: D:\devtools\jdk1.6.0_11\jre
Default locale: zh_CN, platform. encoding: GBK
OS name: "windows xp" version: "5.1" arch: "x86" Family: "windows"
D:\src\netty_websocket> jmeter -v
Copyright (c) 1998-2008 The Apache Software Foundation
Version 2.3.2 r665936
1.1 增加Pom.xml依赖
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.0.4</version>
</dependency>
<dependency>
<groupId>logkit</groupId>
<artifactId>logkit</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>maven-jmeter-plugin</artifactId>
<version>1.0</version>
</dependency>
1.2 Maven mvn.bat调整
Maven工程bin/Mvn.bat运行参数增加CLASSPATH指示器。
%MAVEN_JAVA_EXE% %MAVEN_OPTS% -classpath %CLASSWORLDS_JAR%;"C:\Documents and Settings\jianzhao.liangjz\.m2\repository\commons-logging\commons-logging\1.0.4\commons-logging-1.0.4.jar";"C:\Documents and Settings\jianzhao.liangjz\.m2\repository\logkit\logkit\1.0.1\logkit-1.0.1.jar" "-Dclassworlds.conf=%M2_HOME%\bin\m2.conf" "-Dmaven.home=%M2_HOME%" org.codehaus.classworlds.Launcher %MAVEN_CMD_LINE_ARGS%
1.3 拷贝upgrade.properties到工程bin/目录下
拷贝jmeter/bin下文件upgrade.properties到如D:\src\netty_websocket\bin目录下
1.4 创建一个jmx文件
用badboy录制google搜索过程,另存jmeter文件为google_search.jmx。
放到D:\src\netty_websocket\src\test\jmeter目录下
1.5 执行命令生成XML报告
可以mvn jmeter:jmeter,也可mvn verify。
结果文件在D:\src\netty_websocket\target\jmeter-reports\ google_search*.xml
1.6 生成html报告(可选)
参考http://jlorenzen.blogspot.com/2008/03/a
Automated Performance Tests using JMeter and Maven
· Under your project create the directory:src/test/jmeterandsrc/test/resources
· Copy thejmeter.propertiesfile from the JMeterbinfolder tosrc/test/jmeter.
· Update the propertyjmeter.save.saveservice.output_formatin thejmeter.propertiesfile from csv to xml.
· Copy the filesjmeter-results-detail-report_21.xslandjmeter-results-report_21.xslfrom the JMeterextrasfolder tosrc/test/resources
. pom.xml add
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xml-maven-plugin</artifactId>
<version>1.0-beta-2</version>
<executions>
<execution>
<phase>pre-site</phase>
<goals>
<goal>transform</goal>
</goals>
</execution>
</executions>
<configuration>
<transformationSets>
<transformationSet>
<dir>${project.build.directory}/jmeter-reports</dir>
<stylesheet>src/test/resources/jmeter-results-detail-report_21.xsl</stylesheet>
<outputDir>${project.build.directory}/site/jmeter-results</outputDir>
<fileMappers>
<fileMapper implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
<targetExtension>html</targetExtension>
</fileMapper>
</fileMappers>
</transformationSet>
</transformationSets>
</configuration>
</plugin>
<>