1
votes

I am using Jmeter Maven plugin( http://jmeter.lazerycode.com) to trigger jmx files in my maven project. Is there a way where I can specify which jmx file to run during run time instead of the plugin configuration testFilesDirectory, testFilesExcluded, testFilesIncluded etc in the pom.xml. In jmeter command line mode we can specify using -t.

jmeter -n -t mytest.jmx

Is there a similar option in the jmeter maven plugin

1

1 Answers

1
votes

What's wrong with this <testFilesIncluded> tag?

If you define a Maven Property like

<properties>
    <jmeterScript>test1.jmx</jmeterScript>
</properties>

And refer it in the JMeter Maven plugin as:

<configuration>
    <testFilesIncluded>
        <jMeterTestFile>${jmeterScript}</jMeterTestFile>
    </testFilesIncluded>
</configuration>

You will be able to override the property value using -D command-line argument like:

mvn -DjmeterScript=someTest.jmx clean verify

or

mvn -DjmeterScript=someOtherTest clean verify 

Full pom.xml file just in case:

<?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>com.example</groupId>
    <artifactId>jmeter</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <jmeterScript>test1.jmx</jmeterScript>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>com.lazerycode.jmeter</groupId>
                <artifactId>jmeter-maven-plugin</artifactId>
                <version>2.8.5</version>
                <executions>
                    <!-- Run JMeter tests -->
                    <execution>
                        <id>jmeter-tests</id>
                        <goals>
                            <goal>jmeter</goal>
                        </goals>
                    </execution>
                    <!-- Fail build on errors in test -->
                    <execution>
                        <id>jmeter-check-results</id>
                        <goals>
                            <goal>results</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <testFilesIncluded>
                        <jMeterTestFile>${jmeterScript}</jMeterTestFile>
                    </testFilesIncluded>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

More information: