答案 0 :(得分:1)
我会选择Sample Variables,因此您可以将用户名包含在.jtl结果文件中,添加如下代码:
在JUnit中:
JUnitSampler sampler = new JUnitSampler();
JMeterVariables vars = sampler.getThreadContext().getVariables();
vars.put("username", your_username_variable);
vars.put("elapsed", your_total_time_variable);
sampler.getThreadContext().setVariables(vars);
在JMeter的 user.properties 文件中:
sample_variables=username,elapsed
如果您想要一个单独的文件 - 只需将所有System.out.println("");
替换为:
FileUtils.writeStringToFile(new File("/path/to/file"),"what you need to write", true);
有关使用JMeter运行JUnit测试的更多信息,请参阅How to Use JUnit With JMeter文章
答案 1 :(得分:0)
如果您不想创建单独的文件并且可以使用日志文件,则下面的语句将写入日志文件
log.info(" TEXT ");
如果要创建单独的文件,则
import org.apache.jmeter.services.FileServer;
f = new FileOutputStream("c:/output/result.txt", true);
p = new PrintStream(f);
p.println(" Hello World "); // update here what you want to write
p.close();
f.close();
答案 2 :(得分:0)
1:将JSR223采样器添加到您的测试计划
2:写下面的代码:
FileWriter fstream = new FileWriter("D:\\subid.csv",true); //Create New file with name "subid"
BufferedWriter out = new BufferedWriter(fstream);
out.write(vars.get("variable1"));//write value of variable 1
out.write(",");
out.write(vars.get("variable2"));//write value of variable 2
out.write(System.getProperty("line.separator"));//insert new line
out.close();
fstream.close();