首页 > 其他分享 >Jmeter+Maven接口自动化搭建

Jmeter+Maven接口自动化搭建

时间:2023-02-03 16:11:55浏览次数:44  
标签:maven jmeter src -- 接口 Maven html test Jmeter

1.Jmeter脚本

录制/编写Jmeter脚本(不做描述)

2.Maven项目配置

1、创建一个Maven工程

 

 

 

 

 

 

 

 

 

 

  2、在src/test目录下新建一个jmeter的目录,用来存放jmeter脚本、配置文件、参数化文件;

 

 

 

 3、将需要运行的jmx文件放置在src/test/jmeter目录下,将jmeter bin目录下的配置文件拷贝到src/test/jmeter目录下;

 

 

 

4、修改jmeter.properties文件中的属性值;

 

 

 

 

 

 

 5、在src/test目录下新建一个resources的目录,并将它在项目属性中设置为Test resource用来存放资源文件;

 

 

 

 

 

 

 

 

 

 6、修改pom.xml文件中的配置,该文件是maven的引入jar包、插件的重要配置文件;

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

   <name>JmeterMavenAuto</name>
   <!-- FIXME change it to the project's website -->
  
<url>http://www.example.com</url>

   <properties>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      <maven.compiler.source>1.7</maven.compiler.source>
      <maven.compiler.target>1.7</maven.compiler.target>
      <jmeter.result.jtl.dir>${project.build.directory}jmeteresults</jmeter.result.jtl.dir>
      <jmeter.result.html.dir>${project.build.directory}jmeterhtml</jmeter.result.html.dir>
   </properties>

   <dependencies>
      <dependency>
         <groupId>junit</groupId>
         <artifactId>junit</artifactId>
         <version>4.11</version>
         <scope>test</scope>
      </dependency>
   </dependencies>

   <build>
      <plugins>
         <plugin>
            <!-- 核心插件,用来执行jmx脚本,版本号对应的jmeter版本可在此地址查询 https://github.com/jmeter-maven-plugin/jmeter-maven-plugin/blob/master/CHANGELOG.md-->
           
<groupId>com.lazerycode.jmeter</groupId>
            <artifactId>jmeter-maven-plugin</artifactId>
            <version>3.5.0</version>
            <configuration>

               <!-- 设置jmeter生成结果文件格式-->
              
<resultsFileFormat>xml</resultsFileFormat>
               <!-- 设置忽略失败是否停止运行-->
              
<ignoreResultFailures>true</ignoreResultFailures>
               <!--设置结果是否有时间戳-->
              
<testResultsTimestamp>false</testResultsTimestamp>
               <testFilesIncluded>
                  <!-- //指定运行的jmeter脚本 -->
                 
<jMeterTestFile>baidu.jmx</jMeterTestFile>
               </testFilesIncluded>
               <!-- 指定jtl生成目录 -->
              
<resultsDirectory>${jmeter.result.jtl.dir}</resultsDirectory>
            </configuration>
            <executions>
               <execution>
                  <id>jmeter-tests</id>
                  <phase>verify</phase>
                  <!--脚本所在的文件夹 -->
                 
<goals>
                     <goal>jmeter</goal>
                  </goals>
               </execution>
               <execution>
                  <id>configuration</id>
                  <goals>
                     <goal>configure</goal>
                  </goals>
               </execution>
            </executions>
         </plugin>
         <plugin>
            <!--根据xsl模版把jtl文件转换成html-->
           
<groupId>org.codehaus.mojo</groupId>
            <artifactId>xml-maven-plugin</artifactId>
            <version>1.0-beta-3</version>
            <executions>
               <execution>
                  <phase>verify</phase>
                  <goals>
                     <goal>transform</goal>
                  </goals>
               </execution>
            </executions>
            <configuration>
               <transformationSets>
                  <transformationSet>
                     <dir>${jmeter.result.jtl.dir}</dir>
                     <stylesheet>src\test\resources\jmeter-results-detail-report_21.xsl</stylesheet>
                     <outputDir>${jmeter.result.html.dir}</outputDir>
                     <!-- jtl格式转传承html -->
                    
<fileMappers>
                        <fileMapper
                              implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
                           <targetExtension>html</targetExtension>
                        </fileMapper>
                     </fileMappers>
                  </transformationSet>
               </transformationSets>
            </configuration>
            <!-- using XSLT 2.0 -->
           
<dependencies>
               <dependency>
                  <groupId>net.sf.saxon</groupId>
                  <artifactId>saxon</artifactId>
                  <version>8.7</version>
               </dependency>
            </dependencies>
         </plugin>
      </plugins>
   </build>
</project>

7、Run->Edit Configurations ,Goals里填入verify;

 

 

 

 

3.Maven项目运行

1、运行工程,点击Run或者Maven-verify

 

 

 

 

 

 

 2、执行结果如下表示执行成功,生产相应target文件夹;

 

 

 

 

 

 

 忽略警告,Warning: Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor,因为和提供的XSL样式表文件版本有关系。

3、打开本地项目路径,\JmeterMavenAuto\targetjmeterhtml\baidu.html,用浏览器打开html文件;

 

 

 

 4、html文件图片未加载成功,到jmeter安装目录的extras文件夹中,找到collapse.png、expand.png文件,复制到targetjmeterhtml文件夹中,然后刷新html报表;

 

4.其他说明

1、Jmeter属性设置的3中方式:

第一种:将jmeter.properties、saveservice.properties、system.properties、upgrade.properties、user.properties复制到项目中,进行修改;

第二种:直接在pom.xml文件中进行配置,放在<configuration>节点下;

 

 

 

 第三种:混合配置。

2、如果需要删除不必要的脚本,因为maven项目是会把src/test/jmeter下的测试脚本复制到target/jmeter/testFiles路径下,这两个路径下的脚本都要删除。(若只删除了src下的,则在运行前进行一次clean)

3、在运行maven后发现未生成html文件夹,查看maven-plugins未引入jmeter插件,引入成功后再次运行结果正确。(重新编辑pom.xml文件保存后引入成功)

 

 

 

  

标签:maven,jmeter,src,--,接口,Maven,html,test,Jmeter
From: https://www.cnblogs.com/yanglulu/p/17089595.html

相关文章

  • flea-jersey使用之Flea RESTful接口介绍
    FleaRESTful接口相关文档可参考FleaRESTful接口规范.docx,点击Viewraw即可下载1.总体概述FleaRESTful接口,即遵守REST式风格的接口,基于Jersey开发,遵循JAX-RS规......
  • Maven Use STAR or POSIX extensions to overcome this limit 报错问题解决
     问题:Mavenassembly-plugin在打包的时候如果出现groupid'707420648'istoobig(>2097151). UseSTARorPOSIXextensionstoovercomethislimit解决:只需在......
  • 将 3rd 方 JAR 部署到远程 Maven 库
    1.安装Maven下载地址2.settings.xml配置<?xmlversion="1.0"encoding="UTF-8"?><settingsxmlns="http://maven.apache.org/SETTINGS/1.0.0"xmlns:xs......
  • springcloud:接口文档自动生成器swagger详解 上篇(十一)
    0.引言在微服务的开发工作中,前后端的协同开发是必不可少的,随着服务数与接口数的增加,手写接口文档成为了一个苦活累活,很多程序员对此也很抵触。同时我们也需要有一个地方来......
  • Jmeter 处理MD5加密
    引入MD5加密所需要的jar包。该jar包的名字是:commons-codec-1.9.jarhttps://mvnrepository.com/artifact/commons-codec/commons-codec/1.9 线程组下添加一个前置......
  • 获取访问接口的IP地址(绝对好用)
    在做自动过滤的时候我们经常会将并发访问量非常高的IP进行拉入黑名单,也就是拒绝访问处理,但是我们依然需要收集这些IP地址,那么我们今天就要用到这款代码了,这里是Java的版本我......
  • web应用模式、api接口、接口测试工具postman、restful规范
    引用:https://www.cnblogs.com/liuqingzheng/p/9506212.html今日内容概要web应用模式API接口接口测试工具postmanrestful规范内容详细1、web应用模式#前后端混......
  • 接口
    接口普通类:只有具体实现抽象类:具体实现和规范(抽象方法)都有接口:只有规范,自己无法写方法,专业的约束!约束和实现分离,面向接口编程接口就是规范,定义的是一组规则,体现了......
  • 使用VSCode创建Maven工程测试Java代码
    使用VSCode创建Maven工程测试Java代码发生缘由使用VSCode创建Maven工程测试Java代码环境介绍电脑系统:win10VSCode版本:1.72.0(usersetup)开始搭建搭建......
  • drf快速编写接口
    创建序列化类字段参数fromrest_frameworkimportserializersfromapp01.modelsimportBook举例:classBooksSerializer(serializers.Serializer):name=seria......