问题描述
我正在尝试通过Java为JMX
构建JMETER
文件,以与我的服务自动化框架保持一致。最终,我不想使用JMETER
UI来避免重新生成请求。我在某种程度上已经成功地做到了这一点,但是问题是我无法创建可以使用多个输入的JMX
文件。
通常,这是通过JMETER
数据集配置在CSV
UI中实现的。有人可以通过CSV
使用来自JAVA
的各种数据来帮助我实现并行请求加载吗?
请在下面找到我现在正在使用的采样器代码。
examplecomSampler.setName("Test");
examplecomSampler.setDomain("SampleDomain");
examplecomSampler.setPort("Sample Port");
examplecomSampler.setPath("Sample Path");
examplecomSampler.setMethod("Test");
examplecomSampler.setProtocol("https");
examplecomSampler.addNonEncodedArgument("",strjson,"");
examplecomSampler.setProperty(TestElement.TEST_CLASS,HTTPSamplerProxy.class.getName());
examplecomSampler.setProperty(TestElement.GUI_CLASS,HttpTestSampleGui.class.getName());
解决方法
是的,我们可以通过JMETER
在JAVA
中帮助您实现这一目标。
CSV DATA SET CONFIG
就像您使用HTTP REQUEST
采样器进行的ADDED
方式一样SAME
相关的CLASS
是CSVDataSet。如果您需要在EXAMPLE
中使用JAVA
,请参考SOME
CODE
CSVDataSet csvDataSet = new CSVDataSet();
csvDataSet.setName("CSV Data Set Config");
csvDataSet.setProperty("delimiter",",");
csvDataSet.setProperty("filename","/path/to/your/file.csv");
csvDataSet.setProperty("fileEncoding","UTF-8");
csvDataSet.setProperty("ignoreFirstLine",false);
csvDataSet.setProperty("quotedData",false);
csvDataSet.setProperty("recycle",true);
csvDataSet.setProperty("shareMode","shareMode.all");
csvDataSet.setProperty("stopThread",false);
csvDataSet.setProperty("variableNames","your_variable_name");
csvDataSet.setProperty(TestElement.TEST_CLASS,CSVDataSet.class.getName());
csvDataSet.setProperty(TestElement.GUI_CLASS,TestBeanGUI.class.getName());
更多信息:Five Ways To Launch a JMeter Test without Using the JMeter GUI