先上pom.xml配置:
1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 2 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 3 <modelVersion>4.0.0</modelVersion> 4 <groupId>com.tongdun</groupId> 5 <artifactId>jmeter-demo</artifactId> 6 <packaging>jar</packaging> 7 <version>1.0-SNAPSHOT</version> 8 <name>jmeter-demo</name> 9 <url>http://maven.apache.org</url> 10 11 12 13 <!-- <dependencyManagement> --> 14 <dependencies> 15 <dependency> 16 <groupId>kg.apc</groupId> 17 <artifactId>jmeter-plugins-casutg</artifactId> 18 <version>2.1</version> 19 </dependency> 20 <dependency> 21 <groupId>kg.apc</groupId> 22 <artifactId>jmeter-plugins-graphs-basic</artifactId> 23 <version>2.0</version> 24 </dependency> 25 <dependency> 26 <groupId>kg.apc</groupId> 27 <artifactId>jmeter-plugins-graphs-additional</artifactId> 28 <version>2.0</version> 29 </dependency> 30 </dependencies> 31 <!-- </dependencyManagement> --> 32 33 34 35 <build> 36 <plugins> 37 38 <plugin> 39 <groupId>org.apache.maven.plugins</groupId> 40 <artifactId>maven-dependency-plugin</artifactId> 41 <version>2.8</version> 42 <executions> 43 <execution> 44 <phase>package</phase> 45 <goals> 46 <goal>copy-dependencies</goal> 47 </goals> 48 </execution> 49 </executions> 50 <configuration> 51 <includeArtifactIds>jmeter-plugins-casutg,jmeter-plugins-graphs-basic,jmeter-plugins-graphs-additional</includeArtifactIds> 52 <outputDirectory>target/jmeter/lib/ext</outputDirectory> 53 </configuration> 54 </plugin> 55 56 <!-- <plugin> 57 <groupId>kg.apc</groupId> 58 <artifactId>jmeter-plugins-casutg</artifactId> 59 <version>2.1</version> 60 <executions> 61 <execution> 62 <id>copy-dependencies</id> 63 <phase>package</phase> 64 <goals> 65 <goal>copy-dependencies</goal> 66 </goals> 67 <configuration> 68 <outputDirectory>/var/lib/jenkins/workspace/jmeter-demo/target/jmeter/lib/ext</outputDirectory> 69 <overWriteReleases>false</overWriteReleases> 70 <overWriteSnapshots>false</overWriteSnapshots> 71 <overWriteIfNewer>true</overWriteIfNewer> 72 </configuration> 73 </execution> 74 </executions> 75 </plugin> --> 76 <plugin> 77 <groupId>com.lazerycode.jmeter</groupId> 78 <artifactId>jmeter-maven-plugin</artifactId> 79 <!-- <version>1.10.0</version> --> 80 <executions> 81 <execution> 82 <id>jmeter-tests</id> 83 <phase>verify</phase> 84 <goals> 85 <goal>jmeter</goal> 86 <!-- <goal>copy</goal> --> 87 </goals> 88 </execution> 89 </executions> 90 91 <configuration> 92 <appendResultsTimestamp>true</appendResultsTimestamp> 93 <resultsFileNameDateFormat>yyyyMMddHHmmss</resultsFileNameDateFormat> 94 <propertiesUser> 95 <test_url>${webapp.url}</test_url> 96 <port>${webapp.port}</port> 97 </propertiesUser> 98 99 <propertiesJMeter> 100 <test_url>${webapp.url}</test_url> 101 <port>${webapp.port}</port> 102 </propertiesJMeter> 103 </configuration> 104 105 </plugin> 106 107 <plugin> 108 <groupId>com.lazerycode.jmeter</groupId> 109 <artifactId>jmeter-analysis-maven-plugin</artifactId> 110 <executions> 111 <execution> 112 <phase>verify</phase> 113 <goals> 114 <goal>analyze</goal> 115 </goals> 116 <configuration> 117 <source>${project.build.directory}/**/*.jtl</source> 118 <targetDirectory>${project.build.directory}/results</targetDirectory> 119 <processAllFilesFound>true</processAllFilesFound> 120 </configuration> 121 </execution> 122 </executions> 123 </plugin> 124 </plugins> 125 </build> 126 <properties> 127 <webapp.url>http</webapp.url> 128 <webapp.port>80</webapp.port> 129 <!-- <project.build.directory>/Users/zzf/test/jmeter-demo/target/jmeter</project.build.directory> --> 130 </properties> 131 </project>
1、maven使用jmeter进行性能测试的时候,所使用的jmeter插件,只有jmeter默认自带的插件
2、图示jmeter配置中带“@”符号的,都是扩展插件的功能
3、如何在maven使用场景下使用扩展插件?
方法就是在pom.xml里添加依赖,把需要的插件通过依赖下载下来,然后再把依赖拷贝到项目的jmeter的扩展插件路径下jmeter/lib/ext
添加依赖:
1 <dependencies> 2 <dependency> 3 <groupId>kg.apc</groupId> 4 <artifactId>jmeter-plugins-casutg</artifactId> 5 <version>2.1</version> 6 </dependency> 7 <dependency> 8 <groupId>kg.apc</groupId> 9 <artifactId>jmeter-plugins-graphs-basic</artifactId> 10 <version>2.0</version> 11 </dependency> 12 <dependency> 13 <groupId>kg.apc</groupId> 14 <artifactId>jmeter-plugins-graphs-additional</artifactId> 15 <version>2.0</version> 16 </dependency> 17 </dependencies>
copy依赖到jmeter扩展插件所在路径下
1 <build> 2 <plugins> 3 <plugin> 4 <groupId>org.apache.maven.plugins</groupId> 5 <artifactId>maven-dependency-plugin</artifactId> 6 <version>2.8</version> 7 <executions> 8 <execution> 9 <phase>package</phase> 10 <goals> 11 <goal>copy-dependencies</goal> 12 </goals> 13 </execution> 14 </executions> 15 <configuration> 16 <includeArtifactIds>jmeter-plugins-casutg,jmeter-plugins-graphs-basic,jmeter-plugins-graphs-additional</includeArtifactIds> 17 <outputDirectory>target/jmeter/lib/ext</outputDirectory> 18 </configuration> 19 </plugin> 20 </plugins> 21 </build>
includeArtifactIds表示只拷贝指定的插件,多个插件之间,逗号分割,不然会拷贝大量的无关插件