1、创建脚本
点击新建脚本
选择maven工程
复制地址
2、从控制台将 maven项目导入IDEA
将步骤1的最后那张图的地址放到这里,checkout就可以了,如果当时checkout是灰色的,不能选,就重新打开一次,那个地址已经在里面了,然后选中checkout
3、导入相关依赖包
之前不太懂,所以搞得很麻烦,后面经人提醒,在源码的根目录下面有这两份文件,它的lib目录下放着三个jar包,将那三个jar包放在相关目录下,直接运行就可以了
若有缺少的包,可参考博客手工导入
https://blog.csdn.net/weixin_42118880/article/details/107689644
pom.xml文件:
<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>ngrinder</groupId>
<artifactId>blog.csdn.net</artifactId>
<version>0.0.1</version>
<properties>
<ngrinder.version>3.4.2</ngrinder.version>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>ngrinder.maven.repo</id>
<url>https://github.com/naver/ngrinder/raw/ngrinder.maven.repo/releases</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.ngrinder</groupId>
<artifactId>ngrinder-groovy</artifactId>
<version>${ngrinder.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.sf.grinder</groupId>
<artifactId>grinder-core</artifactId>
<version>3.9.1</version>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>org.ngrinder</groupId>
<artifactId>ngrinder-core</artifactId>
<version>${ngrinder.version}</version>
</dependency>
<dependency>
<groupId>org.ngrinder</groupId>
<artifactId>ngrinder-sh</artifactId>
<version>${ngrinder.version}</version>
</dependency>
<!-- For UnitTest -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit-dep</artifactId>
<version>4.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>grinder</groupId>
<artifactId>grinder-patch</artifactId>
<version>3.9.1-patch</version>
</dependency>
<dependency>
<groupId>net.sf.grinder</groupId>
<artifactId>grinder-http</artifactId>
<version>3.9.1</version>
</dependency>
<dependency>
<groupId>net.sf.grinder</groupId>
<artifactId>grinder-httpclient</artifactId>
<version>3.9.1</version>
</dependency>
<!-- Commons -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.22</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.22</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2.2</version>
</dependency>
<!-- Add the dependencies -->
<!--
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.0.1</version>
</dependency>
-->
<!-- Put your private library like this -->
<!--
<dependency>
<groupId>your_lib</groupId>
<artifactId>your_lib</artifactId>
<version>your_lib_version</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/hello.jar</systemPath>
</dependency>
-->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<additionalProjectnatures>
<projectnature>
org.eclipse.jdt.groovy.core.groovyNature
</projectnature>
<projectnature>
org.eclipse.m2e.core.maven2Nature
</projectnature>
</additionalProjectnatures>
</configuration>
</plugin>
</plugins>
</build>
</project>
4、执行TestRunner后提示”no Groovy library is defined“
按照以下的博客处理
https://blog.csdn.net/weixin_42118880/article/details/107765171
5、执行TestRunner后提示”java.lang.RuntimeException: Please add -javaagent“
报这个错也是一样的原因:Error running ‘TestRunner’: Please change caller according to com.intellij.openapi.project.IndexNotReadyException documentation
参考博客:
https://blog.csdn.net/weixin_42118880/article/details/107760205
6、运行成功后,如果想本地执行压力测试
可在这里修改
7、运行成功后,将修改后的脚本提交到ngrinder控制台
我这里是全部都提交的
这块不要勾选,这里面的文件有指向maven仓库的文件,如果这个传上去后,程序运行会根据这里文件指向的仓库地址
8、提交到ngrinder控制台,开始测试
创建测试
在脚本处选择你自己刚提交的脚本,测试次数,最大用户数等按自己需求填写
9、点击保存并运行后,等待测试结果
一般第一次运行,这里会失败,少一些jar包,报错日志查看(ngrinder的日志一般在/root/.ngrinder/logs):
10、手工导入jar包的maven脚本
缺少什么jar包,就在linux虚拟机的仓库中导入相应的包
参考博客
https://blog.csdn.net/weixin_42118880/article/details/107689644