有一个java文件,用于创建我的负载测试的一些先决条件。我有一个属性文件,用于这个类文件的一些条目。我想将这个类文件导出到可运行的Jar中,并从JMeter中运行它,以使测试独立(因为我每次在触发测试之前都手动运行这个java文件)。
如何将属性文件与jar文件集成?比如我是否需要将属性文件包含到可运行的jar中?如果是,如何从JMeter向其传递变量?
下面是我的示例Java文件,
package Automation.Test;
import java.io.File;
import java.io.FileReader;
import java.util.*;
public class ImageUtility {
static List<String> stuName = new ArrayList<String>();
static List<String> sitName = new ArrayList<String>();
static List<String> subName = new ArrayList<String>();
static List<String> visName = new ArrayList<String>();
static List<String> modName = new ArrayList<String>();
static String examDate[] = new String[10];
static String envfilePath = System.getProperty("user.dir") + "\\ENV_2.properties";
static Properties p = new Properties();
static int totalimages;
static String stuVal = p.getProperty("StuValue");
static String sitVal = p.getProperty("SitValue");
static String subVal = p.getProperty("SubValue");
static String visValue = p.getProperty("VisValue");
static String Examdate = p.getProperty("Examdates");
static String modVal = p.getProperty("ModValue");
static String stuInstnaceUID;
static String stuUUId;
@SuppressWarnings("unused")
public static void main(String[] args) {
try {
FileReader reader = new FileReader(envfilePath);
p.load(reader);
stuVal = p.getProperty("StuValue");
sitVal = p.getProperty("SitValue");
subVal = p.getProperty("SubValue");
visValue = p.getProperty("VisValue");
Examdate = p.getProperty("Examdates");
modVal = p.getProperty("ModValue");
stuInstnaceUID = p.getProperty("stuInstnaceUIDValue") + p.getProperty("SubValue") + "0";
File[] files = new File(System.getProperty("user.dir") + "\\generated\\").listFiles();
int subN = Integer.parseInt(p.getProperty("SubValue"));
for (String sName : stuName) {
for (String siName : sitName) {
for (int i = 0; i < (Integer.parseInt(p.getProperty("NoOfSubjectsValue"))); i++) {
stuInstnaceUID = p.getProperty("stuInstnaceUIDValue") + subN + "0";
stuUUId = p.getProperty("StuUUIdValue") + subN;
for (String vName : visName) {
if (vName.equals("baseline") || vName.equals("PRE_TREATMENT")) {
Examdate = examDate[0];
} else if (vName.equals("cycle_1")) {
Examdate = examDate[1];
} else if (vName.equals("cycle_2")) {
Examdate = examDate[2];
} else if (vName.equals("cycle_3")) {
Examdate = examDate[3];
}
for (String modtxt : modName) {
}
}
subN++;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
字符串
和示例属性文件:
StuValue=555210
SitValue=98141
SubValue=98167
NoOfSubjectsValue=1
VisValue=baseline
NoofImagesPerVisit=1
ModValue=ct
Examdates=20160616
stuInstnaceUIDValue=1.333.148.217134.
StuUUIdValue=2.25.282782546287287271988767684395420443
型
1条答案
按热度按时间y1aodyip1#
取决于你想要实现的目标:
1.您可以在setUp Thread Group中使用OS Process Sampler运行可执行文件.jar
1.您可以将代码复制到JSR223 Sampler中,并在需要时调用它
1.您可以将.jar放入JMeter ClassPath中,并在需要时从JSR223 Sampler调用它。