Java Jmeter test

Over the weekend, I learned about the load testing using JMeter to assess whether our API calls could withstand heavy usage.

Steps of Implementation

Download

1. Download Jmeter, select any file in Binaries
2. Unzip the entire folder to the desired path

Configuration

3. Execute bin/jmeter.bat file
4. Add a new thread group: Add → Threads → Thread Group

    1. Numbers of Threads: Number of execution sequences
    2. Ramp-up Period: How long does it take to influx?
    3. Loop: number of repetitions

5. Added Http Requests

    1. Add → Sampler → HTTP Request
    2. Select Request types: GET / POST / DELETE … etc.
    3. If there are Request params, parameters must be set
    4. Set logic (if necessary) add→ logical controller
      1. Log in only once Once Only Controller
      2. Other Loop Controller can be set, specify single request loop count
    5. Cookie Manager: If there is a login credential, it needs to be placed outside the login
      1. After logging in, the sessionId will be recorded in the cookie
      2. The function of Cookie Manager is to record the cookie information in the test calling settings and provide subsequent test calling usage (if there is no setting, subsequent APIs that require login will be intercepted, at least in my test case)
    6. Add Listener -> View Result Trees & Summary report test record

Additional information

- Authorization Manager & Header Manager, etc., add them yourself according to API requirements

- Add → Config Element has other configuration files such as variables, etc., which can be added according to the conditions

After setting up, the test shall be good to go, and we can save the Test Plan as .jmx

Use cmd command to execute jmeter testing & generate complete test report including html file

  1. A test file .jmx is required before testing.
  2. Add the path of Jemeter to environment variable, which we have to enter the installation bin path.
  3. Open cmd as system administrator (After setting, you can directly launch the program using cmd command of jmeter.)
  4. Execute output command.

jmeter -n -t test_demo.jmx -l result.jtl -e -o /Users/directory

Jmeter command

-n: Run Jmeter in non-GUI form-t: test_demo.jmx script path

-t: test_demo.jmx script path

-l: result.jtl operation result saving path, .jtl file name cannot be repeated

-e: Generate an HTML report after the script is finished running

-o: Directory for storing HTML reports

The report is available on designated folder after the test is completed.

I think this kind of test is important, especially we can see if the quality and the efficiency of the code can handle the high Concurrency.