zoukankan      html  css  js  c++  java
  • Jmeter案例demo

    由于要用到sso登录,所以需要把代码打成jar包,引入Jmeter中

    由于需要把依赖jar包一并打包引入到Jmeter中,所以需要在pom中增加如下代码块

    <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
            <!--这部分可有可无,加上的话则直接生成可运行jar包-->
            <!--<archive>-->
            <!--<manifest>-->
            <!--<mainClass>${exec.mainClass}</mainClass>-->
            <!--</manifest>-->
            <!--</archive>-->
            <descriptorRefs>
                <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
        </configuration>
    </plugin>

    然后运用命令

    mvn assembly:assembly -Dmaven.test.skip=true

    把打出jar包

    整体的pom文件如下

    <?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.meituan.hbqa.hoteltest</groupId>
        <artifactId>hotel-bizagent-test</artifactId>
        <version>1.0-SNAPSHOT</version>
    
        <distributionManagement>
            <repository>
                <id>meituan-nexus-releases</id>
                <url>http://maven.sankuai.com/nexus/content/repositories/thirdparty/</url>
            </repository>
            <snapshotRepository>
                <id>nexus-snapshots</id>
                <url>http://maven.sankuai.com/nexus/content/repositories/3rdPartySnapshot/</url>
            </snapshotRepository>
        </distributionManagement>
    
        <properties>
            <org.springframework-version>3.1.2.RELEASE</org.springframework-version>
            <!--<org.slf4j-version>1.6.6</org.slf4j-version>-->
            <org.restlet.version>2.0.14</org.restlet.version>
            <org.restlet.ext.servlet.version>2.0.14</org.restlet.ext.servlet.version>
            <zookeeper-version>3.4.3</zookeeper-version>
            <mtthrift-version>1.8.2.1</mtthrift-version>
            <dozer.version>5.4.0</dozer.version>
            <rp.version>1.0</rp.version>
            <xml.file>test.xml</xml.file>
            <hotel-common-lib.version>1.2.2-SNAPSHOT</hotel-common-lib.version>
            <org.springframework-version>4.1.1.RELEASE</org.springframework-version>
            <httpclient.version>4.5.1</httpclient.version>
            <commons-httpclient.version>3.0.1</commons-httpclient.version>
            <commons-collections.version>3.2.1</commons-collections.version>
            <mms-boot.version>1.0.3</mms-boot.version>
            <mtzk-client.version>1.9.0</mtzk-client.version>
            <libthrift.version>0.8.0</libthrift.version>
            <mtrace-http.version>1.1.5</mtrace-http.version>
            <direction>酒店服务端</direction>
            <sub_direction>酒店同舟</sub_direction>
            <extend_direction>同舟平台</extend_direction>
        </properties>
    
        <!--  parent中包含了所有的基础组件的jar和自动化框架相关的jar  测试-->
        <parent>
            <groupId>com.meituan.hbqa.test</groupId>
            <artifactId>hbqa-service-parent</artifactId>
            <version>1.0.4</version>
            <relativePath/>
        </parent>
    
    
        <dependencies>
            <!--<dependency>-->
            <!--<groupId>org.apache.httpcomponents</groupId>-->
            <!--<artifactId>httpclient</artifactId>-->
            <!--<version>${httpclient.version}</version>-->
            <!--</dependency>-->
            <!--<dependency>-->
            <!--<groupId>commons-httpclient</groupId>-->
            <!--<artifactId>commons-httpclient</artifactId>-->
            <!--<version>${commons-httpclient.version}</version>-->
            <!--<exclusions>-->
            <!--<exclusion>-->
            <!--<artifactId>commons-logging</artifactId>-->
            <!--<groupId>commons-logging</groupId>-->
            <!--</exclusion>-->
            <!--</exclusions>-->
            <!--</dependency>-->
            <!--<dependency>-->
            <!--<groupId>com.meituan.hbqa.test</groupId>-->
            <!--<artifactId>hbqa-api-lib</artifactId>-->
            <!--<version>2.2.2</version>-->
            <!--</dependency>-->
            <!--<dependency>-->
            <!--<groupId>com.meituan.hbqa.test</groupId>-->
            <!--<artifactId>hbqa-data-lib</artifactId>-->
            <!--<exclusions>-->
            <!--<exclusion>-->
            <!--<artifactId>log4j</artifactId>-->
            <!--<groupId>log4j</groupId>-->
            <!--</exclusion>-->
            <!--</exclusions>-->
            <!--</dependency>-->
    
            <!--登录场景http://git.sankuai.com/mvc/projects/HBQA/repos/hbqa-login-lib/browse-->
            <dependency>
                <groupId>com.meituan.hbqa</groupId>
                <artifactId>hbqa-login-lib</artifactId>
            </dependency>
    
            <!--mock-client-->
            <!--<dependency>-->
            <!--<groupId>com.meituan.hotel</groupId>-->
            <!--<artifactId>mschedule-client</artifactId>-->
            <!--<version>1.3</version>-->
            <!--<exclusions>-->
            <!--<exclusion>-->
            <!--<artifactId>log4j</artifactId>-->
            <!--<groupId>log4j</groupId>-->
            <!--</exclusion>-->
            <!--<exclusion>-->
            <!--<artifactId>slf4j-log4j12</artifactId>-->
            <!--<groupId>org.slf4j</groupId>-->
            <!--</exclusion>-->
            <!--<exclusion>-->
            <!--<artifactId>slf4j-api</artifactId>-->
            <!--<groupId>org.slf4j</groupId>-->
            <!--</exclusion>-->
            <!--</exclusions>-->
            <!--</dependency>-->
            <!--<dependency>-->
            <!--<groupId>com.sankuai.meituan.ep.mockserver</groupId>-->
            <!--<artifactId>mock-client</artifactId>-->
            <!--<version>1.0.3</version>-->
            <!--</dependency>-->
            <!--<dependency>-->
            <!--<groupId>commons-collections</groupId>-->
            <!--<artifactId>commons-collections</artifactId>-->
            <!--<version>${commons-collections.version}</version>-->
            <!--</dependency>-->
    
            <!--&lt;!&ndash;json数据处理&ndash;&gt;-->
            <!--<dependency>-->
            <!--<groupId>com.alibaba</groupId>-->
            <!--<artifactId>fastjson</artifactId>-->
            <!--</dependency>-->
    
            <!--&lt;!&ndash;auto-thrift-tool&ndash;&gt;-->
            <!--<dependency>-->
            <!--<groupId>com.sankuai.hbqa</groupId>-->
            <!--<artifactId>auto-thrift-tool</artifactId>-->
            <!--<version>1.9.3</version>-->
            <!--<exclusions>-->
            <!--<exclusion>-->
            <!--<artifactId>log4j-api</artifactId>-->
            <!--<groupId>org.apache.logging.log4j</groupId>-->
            <!--</exclusion>-->
            <!--</exclusions>-->
            <!--</dependency>-->
            <!--&lt;!&ndash;lbs&ndash;&gt;-->
            <!--<dependency>-->
            <!--<groupId>com.sankuai.travel.top</groupId>-->
            <!--<artifactId>lbs-client</artifactId>-->
            <!--<version>1.0.3</version>-->
            <!--</dependency>-->
    
            <!--&lt;!&ndash; spring &ndash;&gt;-->
            <!--<dependency>-->
            <!--<groupId>org.springframework</groupId>-->
            <!--<artifactId>spring-core</artifactId>-->
            <!--<version>${org.springframework-version}</version>-->
            <!--<exclusions>-->
            <!--&lt;!&ndash; Exclude Commons Logging in favor of SLF4j &ndash;&gt;-->
            <!--<exclusion>-->
            <!--<groupId>commons-logging</groupId>-->
            <!--<artifactId>commons-logging</artifactId>-->
            <!--</exclusion>-->
            <!--</exclusions>-->
            <!--</dependency>-->
            <!--<dependency>-->
            <!--<groupId>org.springframework</groupId>-->
            <!--<artifactId>spring-context</artifactId>-->
            <!--<version>${org.springframework-version}</version>-->
            <!--</dependency>-->
            <!--<dependency>-->
            <!--<groupId>org.springframework</groupId>-->
            <!--<artifactId>spring-context-support</artifactId>-->
            <!--<version>${org.springframework-version}</version>-->
            <!--</dependency>-->
            <!--<dependency>-->
            <!--<groupId>org.springframework</groupId>-->
            <!--<artifactId>spring-orm</artifactId>-->
            <!--<version>${org.springframework-version}</version>-->
            <!--</dependency>-->
            <!--<dependency>-->
            <!--<groupId>org.springframework</groupId>-->
            <!--<artifactId>spring-beans</artifactId>-->
            <!--<version>${org.springframework-version}</version>-->
            <!--</dependency>-->
            <!--<dependency>-->
            <!--<groupId>org.springframework</groupId>-->
            <!--<artifactId>spring-web</artifactId>-->
            <!--<version>${org.springframework-version}</version>-->
            <!--</dependency>-->
            <!--<dependency>-->
            <!--<groupId>org.springframework</groupId>-->
            <!--<artifactId>spring-webmvc</artifactId>-->
            <!--<version>${org.springframework-version}</version>-->
            <!--</dependency>-->
            <!--<dependency>-->
            <!--<groupId>org.springframework</groupId>-->
            <!--<artifactId>spring-test</artifactId>-->
            <!--<version>${org.springframework-version}</version>-->
            <!--</dependency>-->
            <!--<dependency>-->
            <!--<groupId>joda-time</groupId>-->
            <!--<artifactId>joda-time</artifactId>-->
            <!--<version>2.8.2</version>-->
            <!--</dependency>-->
    
            <!--&lt;!&ndash; 产品中心 Goods-UserUtil &ndash;&gt;-->
            <!--<dependency>-->
            <!--<groupId>com.meituan.hotel</groupId>-->
            <!--<artifactId>hotel-goods-user-lib</artifactId>-->
            <!--<version>1.5.2</version>-->
            <!--</dependency>-->
            <!--<dependency>-->
            <!--<groupId>com.meituan.hotel</groupId>-->
            <!--<artifactId>hotel-rs-index-lib</artifactId>-->
            <!--<version>3.1</version>-->
            <!--</dependency>-->
            <!--<dependency>-->
            <!--<groupId>com.meituan.hotel</groupId>-->
            <!--<artifactId>hotel-goods-biz-lib</artifactId>-->
            <!--<version>0.4.2</version>-->
            <!--</dependency>-->
    
            <!--&lt;!&ndash;同舟平台&ndash;&gt;-->
            <!--<dependency>-->
            <!--<groupId>com.sankuai.hotel</groupId>-->
            <!--<artifactId>hotel-biz-agent-lib</artifactId>-->
            <!--<version>1.0.5</version>-->
            <!--</dependency>-->
    
            <!--<dependency>-->
            <!--<groupId>com.sankuai.sjst.ecom</groupId>-->
            <!--<artifactId>epassport-service-client</artifactId>-->
            <!--<version>1.5</version>-->
            <!--</dependency>-->
    
            <!--<dependency>-->
            <!--<groupId>com.mashape.unirest</groupId>-->
            <!--<artifactId>unirest-java</artifactId>-->
            <!--<version>1.4.9</version>-->
            <!--</dependency>-->
    
            <!--&lt;!&ndash;Lyrebird&ndash;&gt;-->
            <!--<dependency>-->
            <!--<groupId>com.meituan.hbqa.test</groupId>-->
            <!--<artifactId>lyrebird-java-client</artifactId>-->
            <!--<version>RELEASE</version>-->
            <!--</dependency>-->
    
        </dependencies>
    
        <!--打jar包依赖-->
    
        <profiles>
            <profile>
                <id>test</id>
                <activation>
                    <activeByDefault>true</activeByDefault>
                </activation>
                <build>
                    <resources>
                        <resource>
                            <directory>src/test/profiles/test</directory>
                        </resource>
                    </resources>
                </build>
            </profile>
        </profiles>
    
    
        <build>
            <pluginManagement>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-archetype-plugin</artifactId>
                        <version>3.0.1</version>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>3.3</version>
                        <configuration>
                            <source>1.7</source>
                            <target>1.7</target>
                            <encoding>UTF-8</encoding>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-resources-plugin</artifactId>
                        <configuration>
                            <encoding>UTF-8</encoding>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <testFailureIgnore>true</testFailureIgnore>
                            <suiteXmlFiles>
                                <suiteXmlFile>${xml.file}</suiteXmlFile>
                            </suiteXmlFiles>
                            <systemProperties>
                                <property>
                                    <name>direction</name>
                                    <value>${direction}</value>
                                </property>
                                <property>
                                    <name>sub_direction</name>
                                    <value>${sub_direction}</value>
                                </property>
                                <property>
                                    <name>extend_direction</name>
                                    <value>${extend_direction}</value>
                                </property>
                            </systemProperties>
                        </configuration>
                    </plugin>
    
    
                    <plugin>
                        <artifactId>maven-assembly-plugin</artifactId>
                        <configuration>
                            <!--这部分可有可无,加上的话则直接生成可运行jar包-->
                            <!--<archive>-->
                            <!--<manifest>-->
                            <!--<mainClass>${exec.mainClass}</mainClass>-->
                            <!--</manifest>-->
                            <!--</archive>-->
                            <descriptorRefs>
                                <descriptorRef>jar-with-dependencies</descriptorRef>
                            </descriptorRefs>
                        </configuration>
                    </plugin>
    
    
                </plugins>
            </pluginManagement>
        </build>
    
    </project>

    打好的jar包如下所示

    转存失败重新上传取消

    将这些jar包导入到jmeter中

    转存失败重新上传取消

    设置并发数量,可参考https://blog.csdn.net/qq_32444825/article/details/81285721

    转存失败重新上传取消

    转存失败重新上传取消

    转存失败重新上传取消

    转存失败重新上传取消

    转存失败重新上传取消

    压测结果展示:

    转存失败重新上传取消

    转存失败重新上传取消

    转存失败重新上传取消

    转存失败重新上传取消

    踩过的坑:

    1.beanshell明明已经拿到Cookie了,为什么一直set不到请求的头部呢

    注意Jmeter是顺序执行的,所以一定要把BeanShell放在http请求之前

    2.教程说把本次压测相关jar包放在lib/ext里,但是出现一个现象,Jmeter假死了:无法添加新组建,原有的调试取样器图标也变成了空白页不生效

    不要把任何jar包放在Jmeter的解压出来的目录,自己定义在非Jmeter任何目录均可

    3.我打了jar,为什么beanshell还是报import找不到呢

    没有把依赖jar包打进去,需要按照上面介绍把依赖jar包都打进来

    4.HTTP请求,下面的信息头管理、请求默认值等,要在HTTP请求的缩进下

    5.引入jar包后运行,报有jar包有多个版本,冲突

    排除掉本地相关dependency依赖

  • 相关阅读:
    Mybatis简单的入门之增删改查
    循环的角度求均值
    谈谈软件设计
    秒杀多线程第四篇 一个经典的多线程同步问题
    (转)dp动态规划分类详解
    P1006 传纸条
    P1005 矩阵取数游戏
    1D1D动态规划优化
    NOI 2009A 诗人小G
    P1078 文化之旅
  • 原文地址:https://www.cnblogs.com/hd92/p/13554772.html
Copyright © 2011-2022 走看看