Apache JMeter: How to Send Multiple Requests and Asserting Responses
What is Apache JMeter?
If you want to test the performance and functionality of your web applications and services, Apache JMeter is an excellent tool. With it, you can simulate a large number of users accessing your application simultaneously. This way, you can identify bottlenecks, measure response times, and ensure your system can handle the expected load.
The features of Apache JMeter include the capability to conduct load and performance testing for various scenarios:
- Web — HTTP, HTTPS (Java, NodeJS, PHP, ASP.NET, …)
- SOAP / REST Webservices
- FTP
- Database via JDBC
- LDAP
- Message-oriented middleware (MOM) via JMS
- Mail — SMTP(S), POP3(S) and IMAP(S)
- Native commands or shell scripts
- TCP
- Java Objects
How to do it:
1. Download and Install Apache JMeter:
- Go to the Apache JMeter website and download the latest version. Apache JMeter 5.6.2 (Requires Java 8+)
- Install JMeter by following the installation instructions provided for your operating system. On Windows, you need to download the binaries and unzip them into your desired path.
- After unzipping the files, run Jmeter by starting the jar file found at: “apache-jmeter-5.6.2\bin\ApacheJMeter.jar”

2. Creating a Test Plan:
Launch JMeter and create a new test plan by right-clicking on “Test Plan” in the tree view and selecting “Add > Threads (Users) > Thread Group.”
3. Configuring Thread Group:
In the Thread Group, you can set the number of users (threads), ramp-up period, and loop count to simulate concurrent requests.
Number of Threads (Users): This option in the Thread Group determines the desired number of users or threads to simulate concurrently in the test.
Ramp-Up Period: The ramp-up period specifies the duration for all users/threads to be fully active as JMeter gradually starts the threads.
The ramp-up period tells JMeter how long to take to “ramp-up” to the full number of threads chosen. If 10 threads are used, and the ramp-up period is 100 seconds, then JMeter will take 100 seconds to get all 10 threads up and running. Each thread will start 10 (100/10) seconds after the previous thread was begun. If there are 30 threads and a ramp-up period of 120 seconds, then each successive thread will be delayed by 4 seconds.

4. Adding HTTP Request Samplers:
Right-click on the Thread Group and select “Add > Sampler > HTTP Request.”
Configure the HTTP Request with the server’s URL, method (GET, POST, etc.), and any necessary parameters.

5. Adding and Configuring Assertions:
You can add assertions to your HTTP Request Sampler to assert the responses. Right-click on the HTTP Request and select “Add > Assertions.” Common assertions include Response Assertion and Duration Assertion.
Here is an example of a simple assertion to check if the response code is 200. Assertions are useful for verifying the accuracy of responses from the server being tested. By using an assertion, you can confirm that your application is delivering the expected results.

6. Running the Test:
After configuring your test plan, save it and click the "Run" button to start the test. JMeter will execute multiple requests simultaneously and verify their responses based on your configured assertions.

7. Viewing Results:
Once the test is finished, you can analyze the results in different formats, such as tables and graphs. Reviewing response times, error rates, and assertion results is essential to pinpoint any problems. Right-click on the HTTP Request and select “Listener > Summary Report.”

Conclusion:
Keep in mind that this is a simple example. JMeter has a collection of features for intricate testing scenarios, such as parameterization, data-driven, and distributed testing. Constantly tailor your JMeter test plan according to the specific requirements of your application.