zoukankan      html  css  js  c++  java
  • 使用Jenkins和Jmeter搭建性能测试平台

    参考文档:http://blog.csdn.net/liuchunming033/article/details/52186157

    jenkins的性能测试结果展现插件:https://wiki.jenkins-ci.org/display/JENKINS/Performance+Plugin

    maven执行使用的jmeter插件:https://github.com/jmeter-maven-plugin/jmeter-maven-plugin

    Jmeter-maven-plugin高级配置之选择测试脚本

    在pom.xml文件中可以指定运行哪些jmx脚本。

    运行所有的测试脚本

    Jmeter默认运行${project.base.directory}/src/test/jmeter文件夹中的所有脚本,下面是示例。

     1 <project>
     2         [...]
     3             <build>
     4                 <plugins>
     5                     <plugin>
     6                         <groupId>com.lazerycode.jmeter</groupId>
     7                         <artifactId>jmeter-maven-plugin</artifactId>
     8                         <version>1.9.0</version>
     9                         <executions>
    10                             <execution>
    11                                 <id>jmeter-tests</id>
    12                                 <phase>verify</phase>
    13                                 <goals>
    14                                     <goal>jmeter</goal>
    15                                 </goals>
    16                             </execution>
    17                         </executions>
    18                     </plugin>
    19                 </plugins>
    20             </build>
    21         [...]
    22     </project>
    View Code

    运行mvn verify即可。

    使用<testFilesIncluded>指定运行的脚本文件

    我们可以通过<testFilesIncluded>这个标签来手动指定jmx文件。样例如下:

     1 <plugin>
     2         <groupId>com.lazerycode.jmeter</groupId>
     3         <artifactId>jmeter-maven-plugin</artifactId>
     4         <version>1.9.0</version>
     5         <executions>
     6              <execution>
     7                  <id>jmeter-tests</id>
     8                  <phase>verify</phase>
     9                  <goals>
    10                      <goal>jmeter</goal>
    11                  </goals>
    12                  <configuration>
    13                       <testFilesIncluded>
    14                           <jMeterTestFile>test1.jmx</jMeterTestFile>
    15                           <jMeterTestFile>test2.jmx</jMeterTestFile>
    16                       </testFilesIncluded>
    17                  </configuration>
    18             </execution>
    19        </executions>
    20     </plugin> 
    View Code

    当我们执行mvn verify时,只有${project.base.directory}/src/test/jmeter文件夹中的test1.jmx、test2.jmx会执行。

    在<testFilesIncluded>中使用正则表达式

    <testFilesIncluded>标签支持正则表达式,下面的示例,指定以foo开头的所有jmx文件。

     
     1 <plugin>
     2                 <groupId>com.lazerycode.jmeter</groupId>
     3                 <artifactId>jmeter-maven-plugin</artifactId>
     4                 <version>1.9.0</version>
     5                 <executions>
     6                     <execution>
     7                         <id>jmeter-tests</id>
     8                         <phase>verify</phase>
     9                         <goals>
    10                             <goal>jmeter</goal>
    11                         </goals>
    12                         <configuration>
    13                             <testFilesIncluded>
    14                                 <jMeterTestFile>foo*.jmx</jMeterTestFile>
    15                             </testFilesIncluded>
    16                         </configuration>
    17                     </execution>
    18                 </executions>
    19             </plugin>
    View Code

    使用<testFilesExcluded>标签反向指定jmx文件

    我们还可以使用排除法,来指定不要运行${project.base.directory}/src/test/jmeter文件夹中的文件。样例:

     
     1 <plugin>
     2                 <groupId>com.lazerycode.jmeter</groupId>
     3                 <artifactId>jmeter-maven-plugin</artifactId>
     4                 <version>1.9.0</version>
     5                 <executions>
     6                     <execution>
     7                         <id>jmeter-tests</id>
     8                         <phase>verify</phase>
     9                         <goals>
    10                             <goal>jmeter</goal>
    11                         </goals>
    12                         <configuration>
    13                             <testFilesExcluded>
    14                                 <excludeJMeterTestFile>test3.jmx</excludeJMeterTestFile>
    15                                 <excludeJMeterTestFile>test4.jmx</excludeJMeterTestFile>
    16                             </testFilesExcluded>
    17                         </configuration>
    18                     </execution>
    19                 </executions>
    20             </plugin>
    View Code

    当我们运行mvn verify时,${project.base.directory}/src/test/jmeter文件夹中除了test3.jmx和test4.jmx,其他的jmx文件都会执行。

    <testFilesExcluded>标签使用正则表达式

    反向指定jmx文件时,也可以使用正则表达式,样例:

     1 <plugin>
     2                 <groupId>com.lazerycode.jmeter</groupId>
     3                 <artifactId>jmeter-maven-plugin</artifactId>
     4                 <version>1.9.0</version>
     5                 <executions>
     6                     <execution>
     7                         <id>jmeter-tests</id>
     8                         <phase>verify</phase>
     9                         <goals>
    10                             <goal>jmeter</goal>
    11                         </goals>
    12                         <configuration>
    13                             <testFilesExcluded>
    14                                 <excludeJMeterTestFile>*bar.jmx</excludeJMeterTestFile>
    15                             </testFilesExcluded>
    16                         </configuration>
    17                     </execution>
    18                 </executions>
    19             </plugin>
    View Code

    运行时,以bar结束的jmx文件都会排除在外。

    <testFilesDirectory>标签指定jmx文件夹

    我们还可以自定义jmx文件的位置(默认是${project.base.directory}/src/test/jmeter)。

     1 <plugin>
     2                 <groupId>com.lazerycode.jmeter</groupId>
     3                 <artifactId>jmeter-maven-plugin</artifactId>
     4                 <version>1.9.0</version>
     5                 <executions>
     6                     <execution>
     7                         <id>jmeter-tests</id>
     8                         <phase>verify</phase>
     9                         <goals>
    10                             <goal>jmeter</goal>
    11                         </goals>
    12                         <configuration>
    13                             <testFilesDirectory>/scratch/testfiles/</testFilesDirectory>
    14                         </configuration>
    15                     </execution>
    16                 </executions>
    17             </plugin>
    View Code

    各个配置含义及解读:https://github.com/jmeter-maven-plugin/jmeter-maven-plugin/wiki/Advanced-Configuration

  • 相关阅读:
    PHP使用iconv函数遍历数组转换字符集
    ping localhost出现地址::1
    在 Windows 7 中禁用IPv6协议/IPv6隧道
    ping localhost 返回 ::1的导致不能打开http://localhost的原因及解决
    [LeetCode] Climbing Stairs
    [LeetCode] Binary Tree Level Order Traversal II
    [LeetCode] Set Mismatch
    [LeetCode] Power of Four
    [LeetCode] Power of Three
    [LeetCode] Power of Two
  • 原文地址:https://www.cnblogs.com/shengulong/p/6646844.html
Copyright © 2011-2022 走看看