• JMeter笔记14 | JMeter场景设计和设置


    1 场景设计

    1.1 什么是场景?

    • 用来真实模拟用户操作的工作单元;
    • 场景设计源自于用户真实操作。

    1.2 设计原则

    • JMeter场景设计通过线程组设置来完成,有些复杂场景需要配合逻辑控制器完成;
    • 原则是忠于用户实际操作,组合用户的各种操作到场景中来。

    2 场景设置

    线程组实际是建立一个线程池,对线程池进行初始化,运行时做各种异常处理。
    在这里插入图片描述

    2.1 参数说明

    2.1 基本参数

    参数说明
    名称任意设置具有业务的意思即可
    注释任意设置,可为空

    2.2 在取样器错误后要执行的动作

    参数说明
    继续请求出错后继续运行
    启动下一进程循环若出错,同一脚本中的请求将不再执行,直接重新开始执行
    停止线程若出错,停止当前线程不再执行
    停止测试某一线程请求失败,停止所有线程,但每个线程执行完当前迭代才会停止
    立即停止测试有线程请求失败,立马停止整个测试场景

    2.3 线程属性

    参数说明
    线程数运行线程的数量,一个线程对应一个虚拟用户
    Ramp-Up Period线程启动开始运行的时间间隔,即所有线程在多长时间内开始运行。若线程数为20,时间为10秒,则每秒启动2个小城。设置为0秒,则表示20个线程立马启动
    循环次数请求的重复次数。选择“永远”则一直执行除非崩溃。不选择“永远”,填写次数,则运行指定的次数。
    延迟创建线程直到需要勾选后,线程在Ramp-Up Period的间隔时间启动并运行取样器的请求。
    Same user on each iteration【选中】每次循环用第一次的cookie,不再更新;可以理解为每次循环都是同一个用户。【不选中】每次循环都是用新的cookie值;可以理解为每次循环都是不同的用户

    2.4 调度器

    参数说明
    持续时间测试计划持续多长时间
    启动延迟点击执行按钮后,仅初始化场景,不运行线程

    3 实例说明

    • 获取token接口,线程数10,时间为5秒,则每秒启动2个;
    • 循环次数设置2;
    • 其他默认;
    • 运行脚本;

    在这里插入图片描述

    • 运行脚本后发现,有20个请求,因为线程数为10,循环了2次。
      在这里插入图片描述

    4 本文涉及的脚本

    <?xml version="1.0" encoding="UTF-8"?>
    <jmeterTestPlan version="1.2" properties="5.0" jmeter="5.3">
      <hashTree>
        <TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="测试计划" enabled="true">
          <stringProp name="TestPlan.comments"></stringProp>
          <boolProp name="TestPlan.functional_mode">false</boolProp>
          <boolProp name="TestPlan.tearDown_on_shutdown">true</boolProp>
          <boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
          <elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="用户定义的变量" enabled="true">
            <collectionProp name="Arguments.arguments">
              <elementProp name="COMMON" elementType="Argument">
                <stringProp name="Argument.name">COMMON</stringProp>
                <stringProp name="Argument.value">/zentao/api.php/v1</stringProp>
                <stringProp name="Argument.metadata">=</stringProp>
              </elementProp>
            </collectionProp>
          </elementProp>
          <stringProp name="TestPlan.user_define_classpath"></stringProp>
        </TestPlan>
        <hashTree>
          <HeaderManager guiclass="HeaderPanel" testclass="HeaderManager" testname="HTTP信息头管理器" enabled="true">
            <collectionProp name="HeaderManager.headers">
              <elementProp name="" elementType="Header">
                <stringProp name="Header.name">Content-Type</stringProp>
                <stringProp name="Header.value">application/json</stringProp>
              </elementProp>
            </collectionProp>
          </HeaderManager>
          <hashTree/>
          <ConfigTestElement guiclass="HttpDefaultsGui" testclass="ConfigTestElement" testname="HTTP请求默认值" enabled="true">
            <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="用户定义的变量" enabled="true">
              <collectionProp name="Arguments.arguments"/>
            </elementProp>
            <stringProp name="HTTPSampler.domain">127.0.0.1</stringProp>
            <stringProp name="HTTPSampler.port">80</stringProp>
            <stringProp name="HTTPSampler.protocol">http</stringProp>
            <stringProp name="HTTPSampler.contentEncoding">UTF-8</stringProp>
            <stringProp name="HTTPSampler.path"></stringProp>
            <stringProp name="HTTPSampler.concurrentPool">6</stringProp>
            <stringProp name="HTTPSampler.connect_timeout"></stringProp>
            <stringProp name="HTTPSampler.response_timeout"></stringProp>
          </ConfigTestElement>
          <hashTree/>
          <ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="禅道接口" enabled="true">
            <stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
            <elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="循环控制器" enabled="true">
              <boolProp name="LoopController.continue_forever">false</boolProp>
              <stringProp name="LoopController.loops">2</stringProp>
            </elementProp>
            <stringProp name="ThreadGroup.num_threads">10</stringProp>
            <stringProp name="ThreadGroup.ramp_time">5</stringProp>
            <boolProp name="ThreadGroup.scheduler">false</boolProp>
            <stringProp name="ThreadGroup.duration"></stringProp>
            <stringProp name="ThreadGroup.delay"></stringProp>
            <boolProp name="ThreadGroup.same_user_on_next_iteration">true</boolProp>
          </ThreadGroup>
          <hashTree>
            <TransactionController guiclass="TransactionControllerGui" testclass="TransactionController" testname="事务控制器" enabled="true">
              <boolProp name="TransactionController.includeTimers">false</boolProp>
              <boolProp name="TransactionController.parent">true</boolProp>
            </TransactionController>
            <hashTree>
              <HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="1-获取token" enabled="true">
                <boolProp name="HTTPSampler.postBodyRaw">true</boolProp>
                <elementProp name="HTTPsampler.Arguments" elementType="Arguments">
                  <collectionProp name="Arguments.arguments">
                    <elementProp name="" elementType="HTTPArgument">
                      <boolProp name="HTTPArgument.always_encode">false</boolProp>
                      <stringProp name="Argument.value">{&quot;account&quot;: &quot;admin&quot;, &quot;password&quot;: &quot;123456&quot;}</stringProp>
                      <stringProp name="Argument.metadata">=</stringProp>
                    </elementProp>
                  </collectionProp>
                </elementProp>
                <stringProp name="HTTPSampler.domain"></stringProp>
                <stringProp name="HTTPSampler.port"></stringProp>
                <stringProp name="HTTPSampler.protocol"></stringProp>
                <stringProp name="HTTPSampler.contentEncoding">UTF-8</stringProp>
                <stringProp name="HTTPSampler.path">/${COMMON}/tokens</stringProp>
                <stringProp name="HTTPSampler.method">POST</stringProp>
                <boolProp name="HTTPSampler.follow_redirects">true</boolProp>
                <boolProp name="HTTPSampler.auto_redirects">false</boolProp>
                <boolProp name="HTTPSampler.use_keepalive">true</boolProp>
                <boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
                <stringProp name="HTTPSampler.embedded_url_re"></stringProp>
                <stringProp name="HTTPSampler.connect_timeout"></stringProp>
                <stringProp name="HTTPSampler.response_timeout"></stringProp>
              </HTTPSamplerProxy>
              <hashTree>
                <JSONPostProcessor guiclass="JSONPostProcessorGui" testclass="JSONPostProcessor" testname="JSON提取器-提取返回的token" enabled="false">
                  <stringProp name="JSONPostProcessor.referenceNames">token</stringProp>
                  <stringProp name="JSONPostProcessor.jsonPathExprs">$.token</stringProp>
                  <stringProp name="JSONPostProcessor.match_numbers">1</stringProp>
                  <stringProp name="JSONPostProcessor.defaultValues"></stringProp>
                </JSONPostProcessor>
                <hashTree/>
                <RegexExtractor guiclass="RegexExtractorGui" testclass="RegexExtractor" testname="正则表达式提取器" enabled="true">
                  <stringProp name="RegexExtractor.useHeaders">false</stringProp>
                  <stringProp name="RegexExtractor.refname">token</stringProp>
                  <stringProp name="RegexExtractor.regex">&quot;token&quot;:&quot;(.*?)&quot;</stringProp>
                  <stringProp name="RegexExtractor.template">$1$</stringProp>
                  <stringProp name="RegexExtractor.default"></stringProp>
                  <stringProp name="RegexExtractor.match_number">1</stringProp>
                </RegexExtractor>
                <hashTree/>
                <ResponseAssertion guiclass="AssertionGui" testclass="ResponseAssertion" testname="响应断言-响应代码" enabled="true">
                  <collectionProp name="Asserion.test_strings">
                    <stringProp name="49587">201</stringProp>
                  </collectionProp>
                  <stringProp name="Assertion.custom_message"></stringProp>
                  <stringProp name="Assertion.test_field">Assertion.response_code</stringProp>
                  <boolProp name="Assertion.assume_success">false</boolProp>
                  <intProp name="Assertion.test_type">2</intProp>
                </ResponseAssertion>
                <hashTree/>
              </hashTree>
            </hashTree>
            <ResultCollector guiclass="TableVisualizer" testclass="ResultCollector" testname="用表格察看结果" enabled="true">
              <boolProp name="ResultCollector.error_logging">false</boolProp>
              <objProp>
                <name>saveConfig</name>
                <value class="SampleSaveConfiguration">
                  <time>true</time>
                  <latency>true</latency>
                  <timestamp>true</timestamp>
                  <success>true</success>
                  <label>true</label>
                  <code>true</code>
                  <message>true</message>
                  <threadName>true</threadName>
                  <dataType>true</dataType>
                  <encoding>false</encoding>
                  <assertions>true</assertions>
                  <subresults>true</subresults>
                  <responseData>false</responseData>
                  <samplerData>false</samplerData>
                  <xml>false</xml>
                  <fieldNames>true</fieldNames>
                  <responseHeaders>false</responseHeaders>
                  <requestHeaders>false</requestHeaders>
                  <responseDataOnError>false</responseDataOnError>
                  <saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage>
                  <assertionsResultsToSave>0</assertionsResultsToSave>
                  <bytes>true</bytes>
                  <sentBytes>true</sentBytes>
                  <url>true</url>
                  <threadCounts>true</threadCounts>
                  <idleTime>true</idleTime>
                  <connectTime>true</connectTime>
                </value>
              </objProp>
              <stringProp name="filename"></stringProp>
            </ResultCollector>
            <hashTree/>
          </hashTree>
          <ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="察看结果树" enabled="true">
            <boolProp name="ResultCollector.error_logging">false</boolProp>
            <objProp>
              <name>saveConfig</name>
              <value class="SampleSaveConfiguration">
                <time>true</time>
                <latency>true</latency>
                <timestamp>true</timestamp>
                <success>true</success>
                <label>true</label>
                <code>true</code>
                <message>true</message>
                <threadName>true</threadName>
                <dataType>true</dataType>
                <encoding>false</encoding>
                <assertions>true</assertions>
                <subresults>true</subresults>
                <responseData>false</responseData>
                <samplerData>false</samplerData>
                <xml>false</xml>
                <fieldNames>true</fieldNames>
                <responseHeaders>false</responseHeaders>
                <requestHeaders>false</requestHeaders>
                <responseDataOnError>false</responseDataOnError>
                <saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage>
                <assertionsResultsToSave>0</assertionsResultsToSave>
                <bytes>true</bytes>
                <sentBytes>true</sentBytes>
                <url>true</url>
                <threadCounts>true</threadCounts>
                <idleTime>true</idleTime>
                <connectTime>true</connectTime>
              </value>
            </objProp>
            <stringProp name="filename"></stringProp>
          </ResultCollector>
          <hashTree/>
        </hashTree>
      </hashTree>
    </jmeterTestPlan>
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
  • 相关阅读:
    ARM 汇编编写 LED 灯
    ELK日志分析系统
    MHA高可用配置及故障切换
    MySQL 高级函数大全(更新完成)
    C# 二十年语法变迁之 C#9参考
    IT运维面试必须具备的排障知识题库
    数据库基础——4.select语句
    k8s无法删除pv,pvc问题
    P8598 [蓝桥杯 2013 省 AB] 错误票据
    司空见惯 - 英雄扫雷鼠
  • 原文地址:https://blog.csdn.net/NoamaNelson/article/details/126406601