Jmeter-maven-plugin高级配置之选择测试脚本(转)

在pom.xml文件中可以指定运行哪些jmx脚本。

运行所有的测试脚本

Jmeter默认运行${project.base.directory}/src/test/jmeter文件夹中的所有脚本,下面是示例。

    <project>
        [...]
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.lazerycode.jmeter</groupId>
                        <artifactId>jmeter-maven-plugin</artifactId>
                        <version>1.9.0</version>
                        <executions>
                            <execution>
                                <id>jmeter-tests</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>jmeter</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        [...]
    </project>

运行mvn verify即可。

使用<testFilesIncluded>指定运行的脚本文件

我们可以通过<testFilesIncluded>这个标签来手动指定jmx文件。样例如下:

    <plugin>
        <groupId>com.lazerycode.jmeter</groupId>
        <artifactId>jmeter-maven-plugin</artifactId>
        <version>1.9.0</version>
        <executions>
             <execution>
                 <id>jmeter-tests</id>
                 <phase>verify</phase>
                 <goals>
                     <goal>jmeter</goal>
                 </goals>
                 <configuration>
                      <testFilesIncluded>
                          <jMeterTestFile>test1.jmx</jMeterTestFile>
                          <jMeterTestFile>test2.jmx</jMeterTestFile>
                      </testFilesIncluded>
                 </configuration>
            </execution>
       </executions>
    </plugin> 

当我们执行mvn verify时,只有${project.base.directory}/src/test/jmeter文件夹中的test1.jmx、test2.jmx会执行。

在<testFilesIncluded>中使用正则表达式

<testFilesIncluded>标签支持正则表达式,下面的示例,指定以foo开头的所有jmx文件。

            <plugin>
                <groupId>com.lazerycode.jmeter</groupId>
                <artifactId>jmeter-maven-plugin</artifactId>
                <version>1.9.0</version>
                <executions>
                    <execution>
                        <id>jmeter-tests</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>jmeter</goal>
                        </goals>
                        <configuration>
                            <testFilesIncluded>
                                <jMeterTestFile>foo*.jmx</jMeterTestFile>
                            </testFilesIncluded>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

使用<testFilesExcluded>标签反向指定jmx文件

我们还可以使用排除法,来指定不要运行${project.base.directory}/src/test/jmeter文件夹中的文件。样例:

            <plugin>
                <groupId>com.lazerycode.jmeter</groupId>
                <artifactId>jmeter-maven-plugin</artifactId>
                <version>1.9.0</version>
                <executions>
                    <execution>
                        <id>jmeter-tests</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>jmeter</goal>
                        </goals>
                        <configuration>
                            <testFilesExcluded>
                                <excludeJMeterTestFile>test3.jmx</excludeJMeterTestFile>
                                <excludeJMeterTestFile>test4.jmx</excludeJMeterTestFile>
                            </testFilesExcluded>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

当我们运行mvn verify时,${project.base.directory}/src/test/jmeter文件夹中除了test3.jmx和test4.jmx,其他的jmx文件都会执行。

<testFilesExcluded>标签使用正则表达式

反向指定jmx文件时,也可以使用正则表达式,样例:

            <plugin>
                <groupId>com.lazerycode.jmeter</groupId>
                <artifactId>jmeter-maven-plugin</artifactId>
                <version>1.9.0</version>
                <executions>
                    <execution>
                        <id>jmeter-tests</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>jmeter</goal>
                        </goals>
                        <configuration>
                            <testFilesExcluded>
                                <excludeJMeterTestFile>*bar.jmx</excludeJMeterTestFile>
                            </testFilesExcluded>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

运行时,以bar结束的jmx文件都会排除在外。

<testFilesDirectory>标签指定jmx文件夹

我们还可以自定义jmx文件的位置(默认是${project.base.directory}/src/test/jmeter)。

            <plugin>
                <groupId>com.lazerycode.jmeter</groupId>
                <artifactId>jmeter-maven-plugin</artifactId>
                <version>1.9.0</version>
                <executions>
                    <execution>
                        <id>jmeter-tests</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>jmeter</goal>
                        </goals>
                        <configuration>
                            <testFilesDirectory>/scratch/testfiles/</testFilesDirectory>
                        </configuration>
                    </execution>
                </executions>

</plugin> 转载请保留链接地址: https://www.yeetrack.com/?p=912

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值