I'm new to JMeter. I found the following code to run a JMeter test plan(.jmx) from JAVA project by using JMeter API StandardJMeterEngine.
But how can I get the execution result as return?
I saw many articles about SampleResult. If this is a solution, can you please provide details about how can I integrate my sampleResult into the existing JMeter test plan.
// JMeter Engine
StandardJMeterEngine jmeter = new StandardJMeterEngine();
// Initialize Properties, logging, locale, etc.
JMeterUtils.loadJMeterProperties("../jmeter.properties");
JMeterUtils.setJMeterHome("../apache-jmeter-2.11");
JMeterUtils.initLogging();
JMeterUtils.initLocale();
SaveService.loadProperties();
// Load existing .jmx Test Plan
FileInputStream in = new FileInputStream("../Integ.jmx");
HashTree testPlanTree = SaveService.loadTree(in);
in.close();
// Run JMeter Test
jmeter.configure(testPlanTree);
jmeter.run();
<how to capture result here?????????????????>
jmeter.exit();
If you want to access the test results directly in Java without the workaround via file output, you can redefine the result collector and get notified for each sample event:
public class MyResultCollector extends ResultCollector {
public MyResultCollector(Summariser summer) {
super(summer);
}
@Override
public void sampleOccurred(SampleEvent e) {
super.sampleOccurred(e);
SampleResult r = e.getResult();
if (r.isSuccessful()) {
System.out.println("Response time in milliseconds: " + r.getTime());
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With