【问题标题】:Is there a way to run only one test from the testplan using Taurus/JMeter?有没有办法使用 Taurus/JMeter 从测试计划中只运行一个测试?
【发布时间】:2021-02-10 00:32:39
【问题描述】:

我正在尝试使用 Taurus 和 JMeter 通过 Gitlab CI 运行性能测试。我有一个 NavWeb.jmx,其中包含许多要测试的端点,但我正在尝试设置两个作业,一个运行整个测试计划,另一个包含一个作业矩阵,您可以在其中选择要测试的端点。

例子:

(run_perf_test_QA 将所有测试一起运行,而 run_single_test 让您选择要运行的测试)

我目前的解决方案是拥有两个 JMX 文件,一个启用测试,另一个禁用测试。然后我使用启用一项特定测试的Taurus "enable" modification。此解决方案并不理想,因为它需要保持 JMeter 脚本的两个副本同步。另一种解决方案是在 YML 中显式禁用每个测试,然后以编程方式启用其中一个。有没有一种方法可以通过一个 JMX 文件来实现这一点,并且不需要在 YML 文件中明确列出每个测试?

【问题讨论】:

    标签: jmeter gitlab-ci taurus


    【解决方案1】:

    您可以在单个测试计划中使用:

    1. Module Controllers - 保留各个端点及其任意组合
    2. Switch Controller - 选择要运行的端点
    3. __P() function - 使端点选择在外部可配置

    测试计划大纲:

    所以

    • 如果您将 JMeter 运行为:

      jmeter -Jtarget=all
      

      它将执行所有 3 个端点

    • 如果您将 JMeter 运行为:

      jmeter -Jtarget=endpoint1
      

      它只会执行endpoint1

    • 等等

    如果您想使用 Taurus 触发测试(但是我看不到 Taurus 的有效用例),您可以通过 -o command-line argument 传递属性,例如:

    bzt -o modules.jmeter.properties.target=all
    

    bzt -o modules.jmeter.properties.target=endpoint1
    

    完整的测试计划以防万一:

    <?xml version="1.0" encoding="UTF-8"?>
    <jmeterTestPlan version="1.2" properties="5.0" jmeter="5.3">
      <hashTree>
        <TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test Plan" 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="User Defined Variables" enabled="true">
            <collectionProp name="Arguments.arguments"/>
          </elementProp>
          <stringProp name="TestPlan.user_define_classpath"></stringProp>
        </TestPlan>
        <hashTree>
          <ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Thread Group" enabled="true">
            <stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
            <elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true">
              <boolProp name="LoopController.continue_forever">false</boolProp>
              <stringProp name="LoopController.loops">1</stringProp>
            </elementProp>
            <stringProp name="ThreadGroup.num_threads">1</stringProp>
            <stringProp name="ThreadGroup.ramp_time">1</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>
            <SwitchController guiclass="SwitchControllerGui" testclass="SwitchController" testname="Switch Controller" enabled="true">
              <stringProp name="SwitchController.value">${__P(target,)}</stringProp>
            </SwitchController>
            <hashTree>
              <ModuleController guiclass="ModuleControllerGui" testclass="ModuleController" testname="all" enabled="true">
                <collectionProp name="ModuleController.node_path">
                  <stringProp name="764597751">Test Plan</stringProp>
                  <stringProp name="764597751">Test Plan</stringProp>
                  <stringProp name="-1948168983">Thread Group</stringProp>
                  <stringProp name="96673">all</stringProp>
                </collectionProp>
              </ModuleController>
              <hashTree/>
              <ModuleController guiclass="ModuleControllerGui" testclass="ModuleController" testname="endpoint1" enabled="true">
                <collectionProp name="ModuleController.node_path">
                  <stringProp name="764597751">Test Plan</stringProp>
                  <stringProp name="764597751">Test Plan</stringProp>
                  <stringProp name="-1948168983">Thread Group</stringProp>
                  <stringProp name="-1837756314">endpoint 1</stringProp>
                </collectionProp>
              </ModuleController>
              <hashTree/>
              <ModuleController guiclass="ModuleControllerGui" testclass="ModuleController" testname="endpoint2" enabled="true">
                <collectionProp name="ModuleController.node_path">
                  <stringProp name="764597751">Test Plan</stringProp>
                  <stringProp name="764597751">Test Plan</stringProp>
                  <stringProp name="-1948168983">Thread Group</stringProp>
                  <stringProp name="-1837756313">endpoint 2</stringProp>
                </collectionProp>
              </ModuleController>
              <hashTree/>
              <ModuleController guiclass="ModuleControllerGui" testclass="ModuleController" testname="endpoint3" enabled="true">
                <collectionProp name="ModuleController.node_path">
                  <stringProp name="764597751">Test Plan</stringProp>
                  <stringProp name="764597751">Test Plan</stringProp>
                  <stringProp name="-1948168983">Thread Group</stringProp>
                  <stringProp name="-1837756312">endpoint 3</stringProp>
                </collectionProp>
              </ModuleController>
              <hashTree/>
            </hashTree>
            <ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="View Results Tree" 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/>
            <TestFragmentController guiclass="TestFragmentControllerGui" testclass="TestFragmentController" testname="all" enabled="false"/>
            <hashTree>
              <ModuleController guiclass="ModuleControllerGui" testclass="ModuleController" testname="Module Controller - endpoint  1" enabled="true">
                <collectionProp name="ModuleController.node_path">
                  <stringProp name="764597751">Test Plan</stringProp>
                  <stringProp name="764597751">Test Plan</stringProp>
                  <stringProp name="-1948168983">Thread Group</stringProp>
                  <stringProp name="-1481272069">Test Fragment - endpoint 1</stringProp>
                </collectionProp>
              </ModuleController>
              <hashTree/>
              <ModuleController guiclass="ModuleControllerGui" testclass="ModuleController" testname="Module Controller - endpoint 2" enabled="true">
                <collectionProp name="ModuleController.node_path">
                  <stringProp name="764597751">Test Plan</stringProp>
                  <stringProp name="764597751">Test Plan</stringProp>
                  <stringProp name="-1948168983">Thread Group</stringProp>
                  <stringProp name="-1481272068">Test Fragment - endpoint 2</stringProp>
                </collectionProp>
              </ModuleController>
              <hashTree/>
              <ModuleController guiclass="ModuleControllerGui" testclass="ModuleController" testname="Module Controller - endpoint 3" enabled="true">
                <collectionProp name="ModuleController.node_path">
                  <stringProp name="764597751">Test Plan</stringProp>
                  <stringProp name="764597751">Test Plan</stringProp>
                  <stringProp name="-1948168983">Thread Group</stringProp>
                  <stringProp name="-1481272067">Test Fragment - endpoint 3</stringProp>
                </collectionProp>
              </ModuleController>
              <hashTree/>
            </hashTree>
            <TestFragmentController guiclass="TestFragmentControllerGui" testclass="TestFragmentController" testname="endpoint 1" enabled="false"/>
            <hashTree>
              <kg.apc.jmeter.samplers.DummySampler guiclass="kg.apc.jmeter.samplers.DummySamplerGui" testclass="kg.apc.jmeter.samplers.DummySampler" testname="endpoint1" enabled="true">
                <boolProp name="WAITING">true</boolProp>
                <boolProp name="SUCCESFULL">true</boolProp>
                <stringProp name="RESPONSE_CODE">200</stringProp>
                <stringProp name="RESPONSE_MESSAGE">OK</stringProp>
                <stringProp name="REQUEST_DATA">Dummy Sampler used to simulate requests and responses
    without actual network activity. This helps debugging tests.</stringProp>
                <stringProp name="RESPONSE_DATA">Dummy Sampler used to simulate requests and responses
    without actual network activity. This helps debugging tests.</stringProp>
                <stringProp name="RESPONSE_TIME">${__Random(50,500)}</stringProp>
                <stringProp name="LATENCY">${__Random(1,50)}</stringProp>
                <stringProp name="CONNECT">${__Random(1,5)}</stringProp>
                <stringProp name="URL"></stringProp>
                <stringProp name="RESULT_CLASS">org.apache.jmeter.samplers.SampleResult</stringProp>
              </kg.apc.jmeter.samplers.DummySampler>
              <hashTree/>
            </hashTree>
            <TestFragmentController guiclass="TestFragmentControllerGui" testclass="TestFragmentController" testname="endpoint 2" enabled="false"/>
            <hashTree>
              <kg.apc.jmeter.samplers.DummySampler guiclass="kg.apc.jmeter.samplers.DummySamplerGui" testclass="kg.apc.jmeter.samplers.DummySampler" testname="endpoint2" enabled="true">
                <boolProp name="WAITING">true</boolProp>
                <boolProp name="SUCCESFULL">true</boolProp>
                <stringProp name="RESPONSE_CODE">200</stringProp>
                <stringProp name="RESPONSE_MESSAGE">OK</stringProp>
                <stringProp name="REQUEST_DATA">Dummy Sampler used to simulate requests and responses
    without actual network activity. This helps debugging tests.</stringProp>
                <stringProp name="RESPONSE_DATA">Dummy Sampler used to simulate requests and responses
    without actual network activity. This helps debugging tests.</stringProp>
                <stringProp name="RESPONSE_TIME">${__Random(50,500)}</stringProp>
                <stringProp name="LATENCY">${__Random(1,50)}</stringProp>
                <stringProp name="CONNECT">${__Random(1,5)}</stringProp>
                <stringProp name="URL"></stringProp>
                <stringProp name="RESULT_CLASS">org.apache.jmeter.samplers.SampleResult</stringProp>
              </kg.apc.jmeter.samplers.DummySampler>
              <hashTree/>
            </hashTree>
            <TestFragmentController guiclass="TestFragmentControllerGui" testclass="TestFragmentController" testname="endpoint 3" enabled="false"/>
            <hashTree>
              <kg.apc.jmeter.samplers.DummySampler guiclass="kg.apc.jmeter.samplers.DummySamplerGui" testclass="kg.apc.jmeter.samplers.DummySampler" testname="endpoint3" enabled="true">
                <boolProp name="WAITING">true</boolProp>
                <boolProp name="SUCCESFULL">true</boolProp>
                <stringProp name="RESPONSE_CODE">200</stringProp>
                <stringProp name="RESPONSE_MESSAGE">OK</stringProp>
                <stringProp name="REQUEST_DATA">Dummy Sampler used to simulate requests and responses
    without actual network activity. This helps debugging tests.</stringProp>
                <stringProp name="RESPONSE_DATA">Dummy Sampler used to simulate requests and responses
    without actual network activity. This helps debugging tests.</stringProp>
                <stringProp name="RESPONSE_TIME">${__Random(50,500)}</stringProp>
                <stringProp name="LATENCY">${__Random(1,50)}</stringProp>
                <stringProp name="CONNECT">${__Random(1,5)}</stringProp>
                <stringProp name="URL"></stringProp>
                <stringProp name="RESULT_CLASS">org.apache.jmeter.samplers.SampleResult</stringProp>
              </kg.apc.jmeter.samplers.DummySampler>
              <hashTree/>
            </hashTree>
          </hashTree>
        </hashTree>
      </hashTree>
    </jmeterTestPlan>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多