Jmeter-Maven-Plugin高级应用:Selecting Tests To Run

时间:2023-03-09 19:25:37
Jmeter-Maven-Plugin高级应用:Selecting Tests To Run

地址:https://github.com/jmeter-maven-plugin/jmeter-maven-plugin/wiki/Advanced-Configuration

Selecting Tests To Run


Running All Tests

To run all tests held in the ${project.base.directory}/src/test/jmeter you just need to run the phase you have assigned to the execution phase.

In the example below the execution phase has been set to verify:

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

So to run all the tests type:

mvn verify

Specifying <testFilesIncluded>

You can explicitly specify which tests in the ${project.base.directory}/src/test/jmeter should be run by using the <jMeterTestFiles> tag:

+---+
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>2.0.3</version>
<executions>
<execution>
<id>jmeter-tests</id>
<goals>
<goal>jmeter</goal>
</goals>
</execution>
</executions>
<configuration>
<testFilesIncluded>
<jMeterTestFile>test1.jmx</jMeterTestFile>
<jMeterTestFile>test2.jmx</jMeterTestFile>
</testFilesIncluded>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>
+---+

This time when you type mvn verify only test1.jmx and test2.jmx will be run.

Specifying <testFilesIncluded> Using Regex

You can also use a regex to specify which tests to include, below is a simple example showing how to include all tests starting with the text foo:

+---+
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>2.0.3</version>
<executions>
<execution>
<id>jmeter-tests</id>
<goals>
<goal>jmeter</goal>
</goals>
</execution>
</executions>
<configuration>
<testFilesIncluded>
<jMeterTestFile>foo*.jmx</jMeterTestFile>
</testFilesIncluded>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>
+---+

Specifying <testFilesExcluded>

Rather than specifying which tests should be run, you could alternatively specify which tests in the ${project.base.directory}/src/test/jmeter you do not wish to run by using the <excludeJMeterTestFiles> tag:

+---+
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>2.0.3</version>
<executions>
<execution>
<id>jmeter-tests</id>
<goals>
<goal>jmeter</goal>
</goals>
</execution>
</executions>
<configuration>
<testFilesExcluded>
<excludeJMeterTestFile>test3.jmx</excludeJMeterTestFile>
<excludeJMeterTestFile>test4.jmx</excludeJMeterTestFile>
</testFilesExcluded>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>
+---+

This time when you type mvn verify all tests in the tests in the${project.base.directory}/src/test/jmeter apart from test3.jmx and test4.jmx will be run.

Specifying <testFilesExcluded> Using Regex

You can also use a regex to specify which tests to exclude, below is a simple example showing how to include all tests ending with the text bar:

+---+
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>2.0.3</version>
<executions>
<execution>
<id>jmeter-tests</id>
<goals>
<goal>jmeter</goal>
</goals>
</execution>
</executions>
<configuration>
<testFilesExcluded>
<excludeJMeterTestFile>*bar.jmx</excludeJMeterTestFile>
</testFilesExcluded>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>
+---+

Specifying The <testFilesDirectory>

You can specify the directory where the test files are located in your file system (by default the plugin will assume they are in ${project.base.directory}/src/test/jmeter)

+---+
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>2.0.3</version>
<executions>
<execution>
<id>jmeter-tests</id>
<goals>
<goal>jmeter</goal>
</goals>
</execution>
</executions>
<configuration>
<testFilesDirectory>/scratch/testfiles/</testFilesDirectory>
</configuration>
</plugin>
</plugins>
</build>
[...]