JMeter中的CSV数据配置

gg0vcinb  于 2023-01-20  发布在  其他
关注(0)|答案(2)|浏览(138)

在我的项目中,我需要为每个线程传递1个值,并且相同的值将被使用任意次。
JMeter中是否有任何选项?

    • 例如:**

我的问题很简单
在线程组中,我将分配2个线程和10个循环(每个线程10个循环)。
我的要求是,我必须为第一个线程使用第一行数据,相同的数据应用于10个循环,为第二个线程使用第二行数据,相同的数据应用于10个循环。
例如:
在csv文件中,我将声明如下:

43
42
45
46

在执行过程中,线程1应该总是占用43,即使是10个循环,线程2应该总是占用42。
如果我在测试计划中只声明了2个线程,那么就不应该使用45和46。

h79rfbju

h79rfbju1#

下面是您可以如何做到这一点:

Thread Group (2 threads, iteration : 1)
+-- Debug Sampler with Name : T-${__threadNum}-${__StringFromFile(/Volumes/HD2/csv.csv, line)}
+-- Loop Controller (Iterations : 10)
    +-- Debug Sampler to show you get what you need : T-${__threadNum}-DS-${line}

测试计划:

<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="2.3" jmeter="2.8-SNAPSHOT.20120923">
  <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.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">2</stringProp>
        <stringProp name="ThreadGroup.ramp_time">1</stringProp>
        <longProp name="ThreadGroup.start_time">1348513661000</longProp>
        <longProp name="ThreadGroup.end_time">1348513661000</longProp>
        <boolProp name="ThreadGroup.scheduler">false</boolProp>
        <stringProp name="ThreadGroup.duration"></stringProp>
        <stringProp name="ThreadGroup.delay"></stringProp>
      </ThreadGroup>
      <hashTree>
        <DebugSampler guiclass="TestBeanGUI" testclass="DebugSampler" testname="T-${__threadNum}-${__StringFromFile(/Volumes/HD2/csv.csv, line)}" enabled="true">
          <boolProp name="displayJMeterProperties">false</boolProp>
          <boolProp name="displayJMeterVariables">true</boolProp>
          <boolProp name="displaySystemProperties">false</boolProp>
        </DebugSampler>
        <hashTree/>
        <LoopController guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true">
          <boolProp name="LoopController.continue_forever">true</boolProp>
          <stringProp name="LoopController.loops">10</stringProp>
        </LoopController>
        <hashTree>
          <DebugSampler guiclass="TestBeanGUI" testclass="DebugSampler" testname="T-${__threadNum}-DS-${line}" enabled="true">
            <boolProp name="displayJMeterProperties">false</boolProp>
            <boolProp name="displayJMeterVariables">true</boolProp>
            <boolProp name="displaySystemProperties">false</boolProp>
          </DebugSampler>
          <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>false</message>
                <threadName>true</threadName>
                <dataType>false</dataType>
                <encoding>false</encoding>
                <assertions>true</assertions>
                <subresults>false</subresults>
                <responseData>false</responseData>
                <samplerData>false</samplerData>
                <xml>false</xml>
                <fieldNames>false</fieldNames>
                <responseHeaders>false</responseHeaders>
                <requestHeaders>false</requestHeaders>
                <responseDataOnError>false</responseDataOnError>
                <saveAssertionResultsFailureMessage>false</saveAssertionResultsFailureMessage>
                <assertionsResultsToSave>0</assertionsResultsToSave>
                <bytes>true</bytes>
                <hostname>true</hostname>
                <threadCounts>true</threadCounts>
                <sampleCount>true</sampleCount>
              </value>
            </objProp>
            <stringProp name="filename"></stringProp>
          </ResultCollector>
          <hashTree/>
        </hashTree>
      </hashTree>
    </hashTree>
  </hashTree>
</jmeterTestPlan>
pxy2qtax

pxy2qtax2#

  • 将线程组循环设置为1。
  • 在CSV数据集配置后**输入所需循环数(在您的情况下为10)的循环控制器。将共享模式设置为:当前线程组。
  • 将HTTP请求采样器添加为Loop Controller的子项,您就得到了它:)

相关问题