1 建立Meaven Project
2 将运行文件放入jmeter文件夹下
3 将jmeter安装目录bin文件下的文件放入jmeter文件夹下
4 将jmeter安装目录下extras文件放入resource目录下
5 编辑pom.xml
<?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>Grit</groupId>
<artifactId>GritJmeter</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<!--此路径用于存储JMeter的原生测试结果文件,比如csv或者jtl-->
<jmeter.result.jtl.dir>${project.build.directory}\jmeter\results</jmeter.result.jtl.dir>
<!--此路径用于存储由模板转换过来的详细的测试结果的html文件-->
<jmeter.result.html.dir>${project.build.directory}\jmeter\html_detail_report</jmeter.result.html.dir>
<!--此路径用于存储由模板转换过来的测试结果的html文件-->
<jmeter.result.html.dir1>${project.build.directory}\jmeter\html_report</jmeter.result.html.dir1>
<ReportName>TestReport</ReportName>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter_core</artifactId>
<version>5.4.3</version>
</dependency>
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter_java</artifactId>
<version>5.4.3</version>
</dependency>
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>jorphan</artifactId>
<version>5.4.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<!--指定jmeter版本号-->
<jmeterVersion>5.4.3</jmeterVersion>
<!-- JVM 设置-->
<jMeterProcessJVMSettings>
<xms>2048</xms>
<xmx>2048</xmx>
</jMeterProcessJVMSettings>
<!--JMeter能够创建.jtl(XML格式)测试结果和csv测试结果。 默认情况下,此插件使用csv格式。这里需要将其切换为xml格式。-->
<resultsFileFormat>xml</resultsFileFormat>
<!--这里是否生成result report需要设置为false,否则运行时会出现“前言中不允许有内容”的报错。
因为若该项为true,无论你在.properties配置文件或者此pom文件中将结果文件的格式显示设置为xml,最后都只会生成csv的结果文件。
而csv的格式无法转换成我们最后需要的html结果文件,就会报上述的错。-->
<generateReports>true</generateReports>
<!--忽略失败-->
<ignoreResultFailures>true</ignoreResultFailures>
<!--报告文件尾部输出时间戳 -->
<appendResultsTimestamp>true</appendResultsTimestamp>
<!--指定日志级别-->
<overrideRootLogLevel>error</overrideRootLogLevel>
<!-- 将任何其他 Java 库添加到 JMeter 的 lib/ext 目录-->
<jmeterExtensions>
<artifact>kg.apc:jmeter-plugins-standard:1.4.0</artifact>
<artifact>kg.apc:jmeter-plugins-extras:1.4.0</artifact>
<artifact>kg.apc:jmeter-plugins-perfmon:2.1</artifact>
<artifact>kg.apc:jmeter-plugins-manager:1.7</artifact>
</jmeterExtensions>
<junitLibraries>
<!-- <artifact>com.lazerycode.junit:junit-test:1.0.0</artifact>-->
</junitLibraries>
<!-- 指定测试用例的路径-->
<testFilesDirectory>src\test\jmeter\</testFilesDirectory>
</configuration>
<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>
</plugin>
</plugins>
</build>
</project>
运行
mvn clean verify
无须安装JMeter,JMeter被运行