Jmeter-maven-plugin高级应用

转载:http://blog.csdn.net/yue530tomtom/article/details/75048144

作者:约会远行


介绍

Jmeter-maven-plugin可以在maven2或者maven3中使用,是在构建时允许运行jmeter作为构建的一部分。具体版本限制请参考官方changelog

基础配置

...
    <plugin>
        <groupId>com.lazerycode.jmeter</groupId>
        <artifactId>jmeter-maven-plugin</artifactId>
        <version>2.1.0</version>
        <executions>
            <execution>
                <id>jmeter-tests</id>
                <goals>
                    <goal>jmeter</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
...
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

高级配置–修改配置属性

插件启动时会自动扫描${project.base.directory}/src/test/jmeter目录下的配置文件

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

插件允提供修改默认属性

方法就是在pom.xml中的配置中明确配置属性和值,pom.xml中明确配置的属性和值会被合并到jmeter的配置文件中,合并操作会覆盖配置文件中相同属性的配置的值。

插件节点名映射配置文件名规律

插件属性节点名格式:文件后缀+文件名。 

propertiesJMeter对应文件JMeter.properties
 
 
  • 1

叶子节点为对应配置文件中属性对应的key,叶子节点的value为配置新值. 

<log_level.jmeter>DEBUG</log_level.jmeter>
 
 
  • 1

即修改配置文件中log_level.jmeter=DEBUG

使用自定义配置文件示例

jmeter.properties

<configuration>
    <propertiesJMeter>
        <log_level.jmeter>DEBUG</log_level.jmeter>
    </propertiesJMeter>
</configuration>
 
 
  • 1
  • 2
  • 3
  • 4
  • 5

propertiesJMeter节点下的节点名对应jmeter.properties中的配置项(下面同),即修改jmeter.properties文件中log_level.jmeter的属性为DEBUG

saveservice.properties

<configuration>
    <propertiesSaveService>
    <HTTPSampler2>org.apache.jmeter.protocol.http.sampler.HTTPSampler2</HTTPSampler2>
    </propertiesSaveService>
</configuration>
 
 
  • 1
  • 2
  • 3
  • 4
  • 5

upgrade.properties

<configuration>
    <propertiesUpgrade>
    <my.old.ClassName>my.new.ClassName</my.old.ClassName>
    </propertiesUpgrade>
</configuration>
 
 
  • 1
  • 2
  • 3
  • 4
  • 5

user.properties

<configuration>
    <propertiesUser>
        <threads>10</threads>
        <testIterations>5</testIterations>
    </propertiesUser>
</configuration>
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

global.properties

<configuration>
    <propertiesGlobal>
        <threads>10</threads>
        <testIterations>5</testIterations>
    </propertiesGlobal>
</configuration>
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

propertiesSystem

<configuration>
    <propertiesSystem>
    <my.system.property>my.system.property.value</my.system.property>
    </propertiesSystem>
</configuration>
 
 
  • 1
  • 2
  • 3
  • 4
  • 5

propertiesReplacedByCustomFiles

以上设置中指定的默认情况下所有属性将与任何现有的属性合并。如果想让它们被替换而不是合并,可以将< propertiesReplacedByCustomFiles >设置为true(它默认是false)。请慎重考虑,合并时属性默认情况下是确保所有属性合并到最新有效版本的JMeter配置文件。如果你覆盖属性文件,但缺少一个属性是必需的JMeter将可能导致无法启动或者功能异常。

<configuration>
    <propertiesReplacedByCustomFiles>${basedir}true</propertiesReplacedByCustomFiles>
</configuration>
 
 
  • 1
  • 2
  • 3

customPropertiesFile

这将允许你设置一个绝对路径的JMeter自定义配置文件(测试依赖)。这相当于在命令行设置–addprop my.properties参数

<configuration>
    <customPropertiesFile>/user/home/myuser/myCustom.properties</customPropertiesFile>
</configuration>
 
 
  • 1
  • 2
  • 3

propertiesFilesDirectory

插件默认将假定配置文件在$ { project.base.directory } / src /test/ jmeter,我们可以指定配置文件所在的目录。

<configuration>
    <propertiesFilesDirectory>/user/home/myuser/properties</propertiesFilesDirectory>
</configuration>
 
 
  • 1
  • 2
  • 3

Remote Start And Stop Of Servers

远程启动和停止jmeter服务器 
设置< startServersBeforeTests >选项:第一次测试启动时runremote命令被送到JMeter将启动在JMeter.properties 定义远程服务器。 
设置< stopServersAfterTests >选项:测试结束时remoteexit命令被送到JMeter.properties 中定义远程服务器,关闭配置中所有服务器。 
< startServersBeforeTests >和< stopServersAfterTests >可以独立地使用。

<configuration>
    <remoteConfig>
        <startServersBeforeTests>true</startServersBeforeTests>
        <stopServersAfterTests>true</stopServersAfterTests>
    </remoteConfig>
</configuration>
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

你可以配置插件为每个单独的测试执行远程启动和停止,通过设置< startAndStopServersForEachTest >变量为true。如果显式设置为true,< startServersBeforeTests >和< stopServersAfterTests > 即使设置也将被忽略。

<configuration>
    <remoteConfig>
        <startAndStopServersForEachTest>
            false
        </startAndStopServersForEachTest>
    </remoteConfig>
</configuration>
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

除了使用所有远程服务器,你可以通过使用指定启动哪些服务器。

<configuration>
    <remoteConfig>
        <startServersBeforeTests>true</startServersBeforeTests>
        <serverList>server1,server2</serverList>
        <stopServersAfterTests>true</stopServersAfterTests>
    </remoteConfig>
</configuration>
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

Adding jar’s to the /lib directory

添加jar到lib

<dependencies>
    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat</artifactId>
        <version>7.0.50</version>
    </dependency>
</dependencies>
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

可以通过添加额外的jar到jmeter的lib/ext目录

<configuration>
    <jmeterExtensions>
        <artifact>kg.apc:jmeter-plugins:pom:1.3.1</artifact>
    </jmeterExtensions>
</configuration>
 
 
  • 1
  • 2
  • 3
  • 4
  • 5

可以通过junitLibraries添加额外的jar到jmeter的lib/junit目录

<configuration>
    <junitLibraries>
        <artifact>com.lazerycode.junit:junit-test:1.0.0</artifact>
    </junitLibraries>
</configuration>
 
 
  • 1
  • 2
  • 3
  • 4
  • 5

Configuring the JVM

配置jvm参数

<configuration>
    <jMeterProcessJVMSettings>
        <xms>1024</xms>
        <xmx>1024</xmx>
        <arguments>
            <argument>-Xprof</argument>
            <argument>-Xfuture</argument>
        </arguments>
    </jMeterProcessJVMSettings>
</configuration>
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

Setting the

<configuration>
    <proxyConfig>
        <host>10.10.10.53</host>
        <port>80</port>
        <username>jimbob</username>
        <password>correct horse battery staple</password>
        <hostExclusions>localhost|*.lazerycode.com</hostExclusions>
    </proxyConfig>
</configuration>
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

Log Levels

<configuration>
    <overrideRootLogLevel>debug</overrideRootLogLevel>
</configuration>
 
 
  • 1
  • 2
  • 3

Selecting Tests To Run

testFilesIncluded 、testFilesExcluded均支持正则表达式
testFilesIncluded
<configuration>
    <testFilesIncluded>
        <jMeterTestFile>test1.jmx</jMeterTestFile>
        <jMeterTestFile>test2.jmx</jMeterTestFile>
    </testFilesIncluded>
</configuration>
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
testFilesExcluded
<configuration>
    <testFilesExcluded>
        <excludeJMeterTestFile>test3.jmx</excludeJMeterTestFile>
        <excludeJMeterTestFile>test4.jmx</excludeJMeterTestFile>
    </testFilesExcluded>
</configuration>
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
testFilesDirectory
<configuration>
    <testFilesDirectory>/scratch/testfiles/</testFilesDirectory>
</configuration>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值