Jmeter-Maven-Plugin高级应用:Modifying Properties

Modifying Properties

Modifying Properties


 

Using Your Own Properties Files

The easiest way to configure JMeter with this plugin is to supply your own properties files. When it starts up the plugin will scan the ${project.base.directory}/src/test/jmeter directory for the following files:

  • jmeter.properties
  • saveservice.properties
  • upgrade.properties
  • system.properties
  • user.properties
  • global.properties

 

Adding Additional Properties To <propertiesJMeter>

It is possible to set properties that configure the main JMeter library. To set those properties you will need to specify each property in your pom.xml in the config element <propertiesJmeter>(The example below shows a property called log_level.jmeter being set).

Each property specified is merged into the JMeter properties file jmeter.properties, it will overwrite any identical properties within the file.

+---+
<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>
                        <propertiesJMeter>
                            <log_level.jmeter>DEBUG</log_level.jmeter>
                        </propertiesJMeter>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    [...]
</project>
+---+

 

Adding Additional Properties To <propertiesSaveService>

It is possible to set properties that configure the Saveservice of the main JMeter library. To set those properties you will need to specify each property in your pom.xml in the config element<propertiesSaveservice> (The example below shows a property called HTTPSampler2 being set).

Each property specified is merged into the JMeter properties file saveservice.properties, it will overwrite any identical properties within the file.

+---+
<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>
                        <propertiesSaveService>
                            <HTTPSampler2>org.apache.jmeter.protocol.http.sampler.HTTPSampler2</HTTPSampler2>
                        </propertiesSaveService>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    [...]
</project>
+---+

 

Adding Additional Properties To <propertiesUpgrade>

It is possible to set properties that are used in the oldValue to newValue upgrade mapping of the main JMeter library. To set those properties you will need to specify each property in yourpom.xml in the config element <propertiesUpgrade>. (The example below shows a property called my.old.ClassName being set).

Each property specified is merged into the JMeter properties file upgrade.properties, it will overwrite any identical properties within the file.

+---+
<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>
                        <propertiesUpgrade>
                            <my.old.ClassName>my.new.ClassName</my.old.ClassName>
                        </propertiesUpgrade>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    [...]
</project>
+---+

 

Adding Additional Properties To <propertiesUser>

JMeter user properties are properties supplied to JMeter that can be used in JMeter tests. To set user properties you will need to specify each property in your pom.xml in the config element<propertiesUser> (The example below shows a property called threads and a propery calledtestIterations being set).

Each property specified is merged into the JMeter properties file user.properties, it will overwrite any identical properties within the file.

+---+
<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>
                        <propertiesUser>
                            <threads>10</threads>
                            <testIterations>5</testIterations>
                        </propertiesUser>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    [...]
</project>
+---+

 

Adding Additional Properties To <propertiesGlobal>

Global properties are properties that are sent to the remote machines. To set those properties you will need to specify each property in your pom.xml in the config element<propertiesGlobal> (The example below shows a property called threads and a property calledtestIterations being set).

Each property specified is merged into the JMeter properties file global.properties, it will overwrite any identical properties within the file.

+---+
<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>
                        <propertiesGlobal>
                            <threads>10</threads>
                            <testIterations>5</testIterations>
                        </propertiesGlobal>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    [...]
</project>
+---+

 

Adding Additional Properties To <propertiesSystem>

JMeter can set system properties, these are global environment properties accessible by all applications running in the same JVM (They are not accessible outside the JVM). To set system properties you will need to specify each property in your pom.xml in the config element<propertiesSystem> (The example below shows a property called my.system.property being set).

Each property specified is merged into the JMeter properties file system.properties, it will overwrite any identical properties within the file.

+---+
<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>
                        <propertiesSystem>
                            <my.system.property>my.system.property.value</my.system.property>
                        </propertiesSystem>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    [...]
</project>
+---+

 

Setting <propertiesReplacedByCustomFiles>

By default all properties specified in the settings above will be merged with any existing properties. If you want them to be replaced instead you can do this by setting<propertiesReplacedByCustomFiles> to true (it is false by default). Please think very carefullybefore doing this, the reason we merge properties by default is to ensure that all properties are merged into the latest valid versions of the properties files supplied with JMeter. If you overwrite the properties files but are missing a property that is required by JMeter things will most likely break.

+---+
<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>
                        <propertiesReplacedByCustomFiles>${basedir}true</propertiesReplacedByCustomFiles>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    [...]
</project>
+---+

 

Specifying A <customPropertiesFile>

This will allow you to set an absolute path to JMeter custom (test dependent) properties file. This is the equivalent of setting " --addprop my.properties" on the command line.

+---+
<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>
                        <customPropertiesFiles>
                            <file>/user/home/myuser/myCustom.properties</file>
                        </customPropertiesFiles>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    [...]
</project>
+---+

 

Specifying The <propertiesFilesDirectory>

You can specify the directory where the .properties 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>
                        <propertiesFilesDirectory>/user/home/myuser/properties</propertiesFilesDirectory>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    [...]
</project>
+---+
posted @ 2016-10-22 11:05  小学生II  阅读(699)  评论(0编辑  收藏  举报