有没有办法使用 Taurus/JMeter 从测试计划中 运行 只有一个测试?

Is there a way to run only one test from the testplan using Taurus/JMeter?

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

示例:

(run_perf_test_QA 运行 将它们全部放在一起,而 run_single_test 让您选择要进行的测试 运行)

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

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

  1. Module Controllers - 保留单个端点及其任意组合
  2. Switch Controller - 选择要 运行
  3. 的端点
  4. __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>