简体   繁体   中英

How to point jmeter properties path to maven downloaded jmeter jar path?

I am quite new to Jmeter and trying to code and run jmeter using JAVA by following:

https://www.blazemeter.com/blog/5-ways-launch-jmeter-test-without-using-jmeter-gui/ https://bitbucket.org/blazemeter/jmeter-from-code/src/master/src/main/java/com/blazemeter/demo/JMeterFromScratch.java

  if (jmeterHome.exists()) {
  File jmeterProperties = new File(jmeterHome.getPath() + slash + "bin" + slash + "jmeter.properties");

            if (jmeterProperties.exists()) {
                //JMeter Engine
                StandardJMeterEngine jmeter = new StandardJMeterEngine();

                //JMeter initialization (properties, log levels, locale, etc)
                JMeterUtils.setJMeterHome(jmeterHome.getPath());
                JMeterUtils.loadJMeterProperties(jmeterProperties.getPath());

Cannot I use like this

 StandardJMeterEngine jmeter = new StandardJMeterEngine();
                JMeterUtils.getJMeterHome();
                JMeterUtils.getJMeterProperties();

I am getting an error when I use the above code

ERROR org.apache.jmeter.save.SaveService - Can't compute checksum for saveservice properties file Exception in thread "main" org.apache.jorphan.util.JMeterError: JMeter requires the checksum of saveservice properties file to continue

Cannot we point to the jmeter jar downloaded through Maven instead of pointing to jmeter property path ? Can anyone help me out ?

The error you're getting indicates that JMeter fails to read saveservice.properties file.

The file is not a part of any JMeter .jar libraries, you will need to have it in the "bin" subfolder of the folder you specify via JMeterUtils.setJMeterHome() function.

If you invoke JMeterUtils.getJMeterHome() function prior to setting it - you will get null and if you refer the value somewhere else - you will get a NPE

Assuming all above:

  1. Make sure to set JMeter home via the aforementioned function prior to running the test
  2. Make sure to have saveservice.properties in that folder

It might be easier to use Taurus tool for unattended programmatic JMeter tests execution, Taurus provides possibility to execute existing JMeter tests and create new ones using simple YAML syntax. See Navigating your First Steps Using Taurus article for more information on the concept

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM