Search code examples
mavengatling

How to specify simulation class of Gatling in command line


I have simple Gatling project and there two simulation classes (SimulationForAzure.scala & OtherSimulation.scala). When I want chhose only one simulation and try to execute command

mvn -Dgatling.simulationClass=org.example.SimulationForAzure gatling:test

or

mvn gatling:test -Dgatling.simulationClass=org.example.SimulationForAzure

I get error:

Unknown lifecycle phase ".simulationClass=org.example.SimulationForAzure". You must specify a valid lifecycle phase or a goal

What is wrong? And how to specify simulation class of Gatling in command line?

My pom.xml is:

<?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>

Here are my classes: Simulations.


Solution

  • I found a solution myself. I changed the pom.xml file. Now it looks like this:

    <?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>
    

    When I execute in PowerShell

    mvn gatling:test '-Dclassname=org.example.SimulationForAzure'
    

    or

    mvn gatling:test '-Dclassname=org.example.OtherSimulation'
    

    everything works as expected.