性能测试使用maven工程说明
1、依赖尽量用maven依赖管理
2、添加jmeter maven依赖
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter_core</artifactId>
<version>3.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.jmeter/ApacheJMeter_java -->
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter_java</artifactId>
<version>3.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.jmeter/jorphan -->
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>jorphan</artifactId>
<version>3.2</version>
</dependency>
<dependency>
<groupId>com.xxx</groupId>
<artifactId>ad</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/xxx-ad-facade-test-0.0.1-SNAPSHOT.jar</systemPath>
</dependency>
3、开发提供客户端jar包放在lib文件夹下,使用maven管理办法如下
<dependency>
<groupId>com.xxxx</groupId>
<artifactId>ad</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/xxx-xxx-test-0.0.1-SNAPSHOT.jar</systemPath>
</dependency>
4、参数文件、jmx文件放在项目根目录下面
5、maven编译jar包,这个jar包括参数文件,pom.xml添加build节点
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include> **/*.xml </include>
<include> **/*.txt </include>
<include> **/*.properties </include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
6、构建命令:-U clean install dependency:copy-dependencies -DoutputDirectory=target/apache-jmeter-3.2/lib 同时复制jar文件到jmeter下面
7、构建shell命令
#在构建目录下创建jmeter目录,在这个目录下面执行jmeter性能测试
mkdir -p $WORKSPACE/target/apache-jmeter-3.2/
#复制jmeter文件到执行测试目录
/bin/cp -r /app/jmeter/apache-jmeter-3.2/* $WORKSPACE/target/apache-jmeter-3.2/
#复制构建的java请求包到jmeter的ext目录下面
cp $WORKSPACE/target/xxx-ad-test-0.0.1-SNAPSHOT.jar $WORKSPACE/target/apache-jmeter-3.2/lib/ext/
#复制参数文件到jmeter bin目录下
cp $WORKSPACE/all_codes_in_a_string.txt $WORKSPACE/target/apache-jmeter-3.2/bin
#复制场景文件到jmeter bin 目录下面
cp $WORKSPACE/*.jmx $WORKSPACE/target/apache-jmeter-3.2/bin
#复制开发客户端jar包(没有用maven库管理的jar包)到ext文件夹下面
cp $WORKSPACE/lib/xxx-ad-facade-test-0.0.1-SNAPSHOT.jar $WORKSPACE/target/apache-jmeter-3.2/lib/ext/
#执行jmeter测试
$WORKSPACE/target/apache-jmeter-3.2/bin/jmeter -n -t AdRequest.jmx -l resutl.jtl
8、构建后操作使用插件:Publish Performance test result report
另外maven打包复制依赖包
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/lib</outputDirectory> <overWriteReleases>false</overWriteReleases> <overWriteSnapshots>false</overWriteSnapshots> <overWriteIfNewer>true</overWriteIfNewer> </configuration> </execution> </executions> </plugin> </plugins> </build>