如何在命令行中指定加特林的模拟类

Art*_*iom 1 maven gatling

我有简单的加特林项目和两个模拟类(SimulationForAzure.scala 和 OtherSimulation.scala)。当我只想选择一种模拟并尝试执行命令时

mvn -Dgatling.simulationClass=org.example.SimulationForAzure gatling:test
Run Code Online (Sandbox Code Playgroud)

或者

mvn gatling:test -Dgatling.simulationClass=org.example.SimulationForAzure
Run Code Online (Sandbox Code Playgroud)

我收到错误:

Unknown lifecycle phase ".simulationClass=org.example.SimulationForAzure". You must specify a valid lifecycle phase or a goal
Run Code Online (Sandbox Code Playgroud)

怎么了?以及如何在命令行中指定加特林的模拟类?

我的 pom.xml 是:

<?xml version="1.0" encoding="UTF-8"?>
<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>org.example</groupId>
  <artifactId>untitled</artifactId>
  <version>1.0-SNAPSHOT</version>

  <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <encoding>UTF-8</encoding>

    <gatling.version>3.3.1</gatling.version>
    <gatling-maven-plugin.version>3.0.5</gatling-maven-plugin.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>io.gatling.highcharts</groupId>
      <artifactId>gatling-charts-highcharts</artifactId>
      <version>${gatling.version}</version>
    </dependency>
    <dependency>
      <groupId>io.gatling</groupId>
      <artifactId>gatling-app</artifactId>
      <version>${gatling.version}</version>
    </dependency>
    <dependency>
      <groupId>io.gatling</groupId>
      <artifactId>gatling-recorder</artifactId>
      <version>${gatling.version}</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>io.gatling</groupId>
        <artifactId>gatling-maven-plugin</artifactId>
        <version>${gatling-maven-plugin.version}</version>
        <executions>
          <execution>
            <goals>
              <goal>test</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
Run Code Online (Sandbox Code Playgroud)

这是我的课程:模拟。

小智 8

如果模拟类位于 src/test/scalagatling.simulationClass属性下则工作正常:

src
   test
       scala
            com.myproject
                  simulation
                      Sim1.scala
                      Sim2.scala
                      ...
Run Code Online (Sandbox Code Playgroud)

pom.xml 中的插件可以保留原样:

            <plugin>
                <groupId>io.gatling</groupId>
                <artifactId>gatling-maven-plugin</artifactId>
                <version>${gatling-maven-plugin.version}</version>
            </plugin>
Run Code Online (Sandbox Code Playgroud)

该命令的工作原理:

mvn gatling:test -Dgatling.simulationClass=com.myproject.simulation.Sim1


Art*_*iom 5

我自己找到了解决方案。我更改了 pom.xml 文件。现在看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<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>org.example</groupId>
  <artifactId>untitled</artifactId>
  <version>1.0-SNAPSHOT</version>

  <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <encoding>UTF-8</encoding>

    <gatling.version>3.3.1</gatling.version>
    <gatling-maven-plugin.version>3.0.5</gatling-maven-plugin.version>

    <className></className>
  </properties>

  <dependencies>
    <dependency>
      <groupId>io.gatling.highcharts</groupId>
      <artifactId>gatling-charts-highcharts</artifactId>
      <version>${gatling.version}</version>
    </dependency>
    <dependency>
      <groupId>io.gatling</groupId>
      <artifactId>gatling-app</artifactId>
      <version>${gatling.version}</version>
    </dependency>
    <dependency>
      <groupId>io.gatling</groupId>
      <artifactId>gatling-recorder</artifactId>
      <version>${gatling.version}</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>io.gatling</groupId>
        <artifactId>gatling-maven-plugin</artifactId>
        <version>${gatling-maven-plugin.version}</version>
        <configuration>
          <simulationClass>${className}</simulationClass>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>
Run Code Online (Sandbox Code Playgroud)

当我在 PowerShell 中执行时

mvn gatling:test '-Dclassname=org.example.SimulationForAzure'
Run Code Online (Sandbox Code Playgroud)

或者

mvn gatling:test '-Dclassname=org.example.OtherSimulation'
Run Code Online (Sandbox Code Playgroud)

一切都按预期进行。