You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用JMeter Maven插件控制测试用例的执行顺序

JMeter Maven插件测试执行顺序控制方案

执行顺序不符合配置的原因

jmeter-maven-plugin默认会对匹配到的测试文件按照文件名自然排序执行,不会遵循<testFilesIncluded>标签中填写的配置顺序,因此会出现你遇到的执行顺序与预期不符的问题。

可实现的控制方案

有两种常用方式可以自定义测试执行顺序:

方案1:修改测试文件名加数字前缀(推荐,配置成本最低)

给需要按顺序执行的测试文件添加升序数字前缀,强制插件按文件名排序的规则匹配你的执行顺序,比如修改文件名为:

  • 001-flow1.jmx
  • 002-flow2.jmx
  • 003-flow3.jmx
    修改完成后,在<testFilesIncluded>中对应修改文件名即可,无需调整其他配置。

方案2:拆分多执行节点配置(无需修改文件名)

如果不希望改动原有测试文件名,可以通过<executions>标签按你需要的顺序分别定义每个测试的执行任务,Maven会按pom中<execution>节点的配置顺序依次执行,参考配置如下:

<build>
  <plugins>
    <plugin>
      <groupId>com.lazerycode.jmeter</groupId>
      <artifactId>jmeter-maven-plugin</artifactId>
      <version>替换为你当前使用的插件版本</version>
      <!-- 全局公共配置可放在此处,所有execution共享 -->
      <configuration>
        <!-- 例如结果输出路径、jmeter系统属性等公共配置 -->
      </configuration>
      <executions>
        <!-- 执行第一个测试:flow1 -->
        <execution>
          <id>run-flow1</id>
          <goals>
            <goal>jmeter</goal>
          </goals>
          <configuration>
            <testFilesIncluded>
              <jMeterTestFile>flows/flow1</jMeterTestFile>
            </testFilesIncluded>
          </configuration>
        </execution>
        <!-- 执行第二个测试:flow2 -->
        <execution>
          <id>run-flow2</id>
          <goals>
            <goal>jmeter</goal>
          </goals>
          <configuration>
            <testFilesIncluded>
              <jMeterTestFile>flows/flow2</jMeterTestFile>
            </testFilesIncluded>
          </configuration>
        </execution>
        <!-- 执行第三个测试:flow3 -->
        <execution>
          <id>run-flow3</id>
          <goals>
            <goal>jmeter</goal>
          </goals>
          <configuration>
            <testFilesIncluded>
              <jMeterTestFile>flows/flow3</jMeterTestFile>
            </testFilesIncluded>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

注意事项

如果使用多执行节点方案,所有公共的JMeter配置可以抽取到插件全局的<configuration>标签中,无需每个execution重复配置,减少冗余。

内容的提问来源于stack exchange,提问作者Moaad Shbita

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.27 18:36:03