有没有一种方法可以使用Taurus / JMeter从测试计划中仅运行一个测试?

时间:2020-10-27 17:01:03

标签: jmeter gitlab-ci taurus

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

示例:

gitlab ci

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

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

1 个答案:

答案 0 :(得分:2)

您可以使用以下单个测试计划进行操作:

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

测试计划大纲:

enter image description here

所以

  • 如果您以以下方式运行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>