1、maven项目
2、已安装JMeter、Jenkins、maven、jdk
环境要求:
jmeter>5.6.2
maven >3.9
jdk>1.8
Jenkins ?
备注:jmeter-maven-plugin 无需下载,可查阅相关地址:GitHub - jmeter-maven-plugin/jmeter-maven-plugin: The JMeter Maven Plugin
打开ij编辑器,File-->New-->Project,选择Maven,点击next,输入Groupid跟ArtifactId(这个目前随便填就好)
1、在maven项目,如果是模块项目的话,可以找一个模块即可,如api模块,在${project.base.directory}/src/test/创建文件夹录jmeter跟resources。(如果只有一个模块,同理)
jmeter文件夹内容存放来源:jmeter安装目录下bin文件下的配置文档+jmeter脚本(需要用来执行的jmeter脚本)
resource目录内容存文档来源:jmeter安装目录下extras文件
resources文件夹需要修改文件类型,在resources文件夹右键-Mark Directory as-test resources Root,如下
整个pom.xml文件内容如下:
4.0.0
Grit
GritJmeter
1.0-SNAPSHOT
UTF-8
UTF-8
${project.build.directory}\jmeter\results
${project.build.directory}\jmeter\html_detail_report
${project.build.directory}\jmeter\html_report
TestReport
org.apache.jmeter
ApacheJMeter_core
5.4.3
org.apache.jmeter
ApacheJMeter_java
5.4.3
org.apache.jmeter
jorphan
5.4.3
com.lazerycode.jmeter
jmeter-maven-plugin
3.6.0
5.4.3
2048
2048
xml
true
true
true
error
kg.apc:jmeter-plugins-standard:1.4.0
kg.apc:jmeter-plugins-extras:1.4.0
kg.apc:jmeter-plugins-perfmon:2.1
kg.apc:jmeter-plugins-manager:1.7
src\test\jmeter\
configuration
configure
jmeter-tests
jmeter
jmeter-check-results
results
properties 字段后的所有内容都是本次添加的jmter相关的配置信息,后续可做复制使用。另外,拿到这个配置内容,一般只需要修改以下内容就好
mvn clean verify
通过编辑器中的LifeCycle中的操作来执行。
非首次则需要执行clean,再执行verify(首次则直接执行verify即可)
执行时控制台日志:
D:\Software\java\jdk1.8.0_181\bin\java.exe "-Dmaven.multiModuleProjectDirectory=D:\Program Files\GitData\GritJmeter" -Dmaven.home=D:\Software\apache-maven-3.9.1 -Dclassworlds.conf=D:\Software\apache-maven-3.9.1\bin\m2.conf -javaagent:D:\Software\ideaIU-2018.3.6.win\lib\idea_rt.jar=17454:D:\Software\ideaIU-2018.3.6.win\bin -Dfile.encoding=UTF-8 -classpath D:\Software\apache-maven-3.9.1\boot\plexus-classworlds-2.6.0.jar;D:\Software\apache-maven-3.9.1\boot\plexus-classworlds.license org.codehaus.classworlds.Launcher -Didea.version=2018.3.6 verify
[INFO] Scanning for projects...
[INFO]
[INFO] --------------------------< Grit:GritJmeter >---------------------------
[INFO] Building GritJmeter 1.0-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- resources:3.3.0:resources (default-resources) @ GritJmeter ---
[INFO] Copying 0 resource
[INFO]
[INFO] --- compiler:3.10.1:compile (default-compile) @ GritJmeter ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- jmeter:3.6.0:configure (configuration) @ GritJmeter ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] C O N F I G U R I N G J M E T E R
[INFO] -------------------------------------------------------
[INFO]
[INFO] Creating test configuration for execution ID: configuration
[INFO] Building JMeter directory structure...
[INFO] Generating JSON Test config...
[INFO] Configuring JMeter artifacts...
[INFO] Populating JMeter directory...
[INFO] Copying extensions to D:\Program Files\GitData\GritJmeter\target\39016a4e-390a-4b18-8df3-fb914d5aa91f\jmeter\lib\ext
Downloading dependencies: true
[INFO] Copying junit libraries to D:\Program Files\GitData\GritJmeter\target\39016a4e-390a-4b18-8df3-fb914d5aa91f\jmeter\lib\junit
Downloading dependencies: true
[INFO] Copying test plan libraries to D:\Program Files\GitData\GritJmeter\target\39016a4e-390a-4b18-8df3-fb914d5aa91f\jmeter\lib
Downloading dependencies: true
[INFO] Configuring JMeter properties...
[INFO]
[INFO] --- resources:3.3.0:testResources (default-testResources) @ GritJmeter ---
[INFO] Copying 6 resources
[INFO]
[INFO] --- compiler:3.10.1:testCompile (default-testCompile) @ GritJmeter ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- surefire:3.0.0:test (default-test) @ GritJmeter ---
[INFO]
[INFO] --- jar:3.3.0:jar (default-jar) @ GritJmeter ---
[INFO] Building jar: D:\Program Files\GitData\GritJmeter\target\GritJmeter-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- jmeter:3.6.0:jmeter (jmeter-tests) @ GritJmeter ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] P E R F O R M A N C E T E S T S
[INFO] -------------------------------------------------------
[INFO]
[INFO] Will generate HTML report in D:\Program Files\GitData\GritJmeter\target\jmeter\reports\cont
[INFO] Executing test: cont.jmx
[INFO] Arguments for forked JMeter JVM: [java, -Xms2048M, -Xmx2048M, -Djava.awt.headless=true, -jar, ApacheJMeter-5.4.3.jar, -d, D:\Program Files\GitData\GritJmeter\target\39016a4e-390a-4b18-8df3-fb914d5aa91f\jmeter, -e, -j, D:\Program Files\GitData\GritJmeter\target\jmeter\logs\cont.jmx.log, -l, D:\Program Files\GitData\GritJmeter\target\jmeter\results\cont-20231017.csv, -n, -o, D:\Program Files\GitData\GritJmeter\target\jmeter\reports\cont, -t, D:\Program Files\GitData\GritJmeter\target\jmeter\testFiles\cont.jmx, -L, ERROR, -Dsun.net.http.allowRestrictedHeaders, true]
[INFO]
[INFO] SLF4J: Class path contains multiple SLF4J bindings.
[INFO] SLF4J: Found binding in [jar:file:/D:/Program%20Files/GitData/GritJmeter/target/39016a4e-390a-4b18-8df3-fb914d5aa91f/jmeter/lib/log4j-slf4j-impl-2.17.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
[INFO] SLF4J: Found binding in [jar:file:/D:/Program%20Files/GitData/GritJmeter/target/39016a4e-390a-4b18-8df3-fb914d5aa91f/jmeter/lib/slf4j-nop-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
[INFO] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
[INFO] SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
[INFO] Creating summariser
[INFO] Created the tree successfully using D:\Program Files\GitData\GritJmeter\target\jmeter\testFiles\cont.jmx
[INFO] Starting standalone test @ Tue Oct 17 11:19:57 CST 2023 (1697512797293)
[INFO] Waiting for possible Shutdown/StopTestNow/HeapDump/ThreadDump message on port 4445
[INFO] summary + 1 in 00:00:04 = 0.3/s Avg: 3033 Min: 3033 Max: 3033 Err: 0 (0.00%) Active: 1 Started: 1 Finished: 0
[INFO] summary + 13 in 00:00:07 = 1.9/s Avg: 529 Min: 9 Max: 5276 Err: 0 (0.00%) Active: 0 Started: 1 Finished: 1
[INFO] summary = 14 in 00:00:10 = 1.3/s Avg: 708 Min: 9 Max: 5276 Err: 0 (0.00%)
[INFO] Tidying up ... @ Tue Oct 17 11:20:08 CST 2023 (1697512808570)
[INFO] ... end of run
[INFO] Completed Test: D:\Program Files\GitData\GritJmeter\target\jmeter\testFiles\cont.jmx
[INFO]
[INFO]
[INFO] --- jmeter:3.6.0:results (jmeter-check-results) @ GritJmeter ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] S C A N N I N G F O R R E S U L T S
[INFO] -------------------------------------------------------
[INFO]
[INFO] Will scan results using format: CSV
[INFO]
[INFO] Parsing results file 'D:\Program Files\GitData\GritJmeter\target\jmeter\results\cont-20231017.csv' as type: CSV
[INFO]
[INFO] -------------------------------------------------------
[INFO] P E R F O R M A N C E T E S T R E S U L T S
[INFO] -------------------------------------------------------
[INFO]
[INFO] Result (.csv) files scanned: 1
[INFO] Successful requests: 16
[INFO] Failed requests: 0
[INFO] Failures: 0.0% (0.0% accepted)
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 57.681 s
[INFO] Finished at: 2023-10-17T11:20:12+08:00
[INFO] ------------------------------------------------------------------------
[INFO] Shutdown detected, destroying JMeter process...
[INFO]
Process finished with exit code 0
cd 到maven项目代码目录下,执行命令
mvn jmeter:configure jmeter:gui
会自动打开jmeter界面
控制台日志
查看日志可知执行的时候获取的配置是默认配置execution ID: default-cli,而不是我们在pom中配置execution ID: configuration
Microsoft Windows [版本 10.0.17763.4974]
(c) 2018 Microsoft Corporation。保留所有权利。
D:\Program Files\GitData\GritJmeter>mvn jmeter:configure jmeter:gui
[INFO] Scanning for projects...
[INFO]
[INFO] --------------------------< Grit:GritJmeter >---------------------------
[INFO] Building GritJmeter 1.0-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- jmeter:3.6.0:configure (default-cli) @ GritJmeter ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] C O N F I G U R I N G J M E T E R
[INFO] -------------------------------------------------------
[INFO]
[INFO] Creating test configuration for execution ID: default-cli
[INFO] Building JMeter directory structure...
[INFO] Generating JSON Test config...
[INFO] Configuring JMeter artifacts...
[INFO] Populating JMeter directory...
[INFO] Copying extensions to D:\Program Files\GitData\GritJmeter\target\caab0619-1b6c-4fcb-b55c-13626e70662f\jmeter\lib\ext
Downloading dependencies: true
[INFO] Copying junit libraries to D:\Program Files\GitData\GritJmeter\target\caab0619-1b6c-4fcb-b55c-13626e70662f\jmeter\lib\junit
Downloading dependencies: true
[INFO] Copying test plan libraries to D:\Program Files\GitData\GritJmeter\target\caab0619-1b6c-4fcb-b55c-13626e70662f\jmeter\lib
Downloading dependencies: true
[INFO] Configuring JMeter properties...
[INFO]
[INFO] --- jmeter:3.6.0:gui (default-cli) @ GritJmeter ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] S T A R T I N G J M E T E R G U I
[INFO] -------------------------------------------------------
[INFO] Arguments for forked JMeter JVM: [java, -Xms2048M, -Xmx2048M, -jar, ApacheJMeter-5.4.3.jar, -d, D:\Program Files\GitData\GritJmeter\target\caab0619-1b6c-4fcb-b55c-13626e70662f\jmeter, -L, ERROR]
[INFO]
这个方式执行速度比较慢
执行完成后会存在一个targer目录
问题1:
testFilesDirectory 元素值只能是目录,不能是文件,不然会提示找到的不是目录类型而报错
问题2:pom.xml报错提示:Element 'configuration' cannot have character [children], because the type's content type is element
解决办法:发现pom文件内容中少了一个<导致。
配置文件中的beans节点下面只能是元素节点,不能有字符或者文本存在
比如,多余的标点符号,点,也有可能是空格。
问题3:执行结果 ,提示jmeter-maven-plugin版本3.6需要maven 版本3.5.2
解决方案:
参考:
Win10系统Jmeter+maven+Jenkins接口自动化环境搭建(一) | 柯南的博客记录