When calling JMeter using pure java, how to get a Generate Summary Results heartbeat in the logs?

Viewed 70

Let's say I'm running JMeter using pure Java. In particular, I am running JMeter using the cucumber technique roughly described here: https://automationcalling.com/2019/04/22/performance-test-framework-cucumberjmetertestng/

I pull in JMeter using the jmeter maven plugin. Then I run a TestNG cucumber test that runs JMeter.

Here is a very rough code snippet of how I am running JMeter:

    StandardJMeterEngine jmeter;
    jmeter = new StandardJMeterEngine();
    File jmeterConfigFile = Paths.get("target", "config.json").toFile();
    Map jmeterConfig = new ObjectMapper().readValue(jmeterConfigFile, Map.class);
    scenario.write("Jmeter config: " + jmeterConfig);
    Map configuration = (Map) ((List) jmeterConfig.get("configurations")).get(0);
    jmeterPath = (String) configuration.get("jmeterDirectoryPath");
    JMeterUtils.loadJMeterProperties(jmeterPath + "\\bin\\jmeter.properties");
    JMeterUtils.setJMeterHome(jmeterPath);
    JMeterUtils.initLocale();

    SaveService.loadProperties();
    jmeter.configure(testPlanTree);
    jmeter.run();

This works pretty great actually. But one big thing is that the logs are super silent while the test is running.

When you run JMeter from the command line, you get a little "Generate Summary Results" where it shows you the test has been running how many success, throughput, some general stats.

enter image description here

How can I get this same thing when running directly from pure java?

1 Answers

Figured it out by reading the JMeter.java class for the nonGUI path. There is something called Summariser. You can use it easily.

    jmeter.configure(testPlanTree);
    Summariser summariser = null;
    String summariserName = JMeterUtils.getPropDefault("summariser.name", "");
    if (summariserName.length() > 0) {
        summariser = new Summariser(summariserName);
    }
    ResultCollector resultCollector = new ResultCollector(summariser);
    resultCollector.setFilename(logFile.getAbsolutePath());
    testPlanTree.add(testPlanTree.getArray()[0], resultCollector);
    jmeter.run();
Related