# How to Use JMeter
## Installation
**JMeter** is a testing tool that can conduct performance and load tests on web applications.
Here is a tutorial on how to [install JMeter](https://www.guru99.com/guide-to-install-jmeter.html). Note that you must have **Java** installed on your computer for it for **JMeter** to work since **JMeter** runs on **Java**.
## GUI Mode
### Create Thread Group
In the folder where you installed JMeter, double click on `bin/jmeter.bat` to launch the GUI.
Now you need to add a **[thread group](https://jmeter.apache.org/usermanual/test_plan.html#thread_group)**. You can do so through the top toolbar:
`Edit > Add > Threads (User) > Thread Group`
You can name your thread group, and set some thread properties:
- **Number of threads (users)**: Number of virtual users (threads).
- **Ramp-up period (seconds)**: How long it takes to reach the total number of threads stated in the test plan.
- **Loop count**: This indicates how many times each thread was supposed to perform the task.
If 100 threads are used, and the ramp-up period is 10 seconds, then JMeter will take 10 seconds to get all 100 threads up and running.

### Add HTTP Requests
Right click your thread group, and then:
`Add > Sampler >HTTP Request`

You can name your HTTP Request, and then set up your web server settings.
For this example, we want to test the GET request to https://jsonplaceholder.typicode.com/posts

If you want to test out an API on localhost, you can configure it like this:

### Add listeners
Add some listeners so you can see the results of your HTTP Request.
Right click on yout HTTP Request, and then:
`Add > Listener > View Results Tree`
`Add > Listener > Summary Report`
`Add > Listener > View Results in Table`

### Save Thread Group
Click on your Thread Group in the left bar, then on the top toolbar:
`File > Save Test Plan as`
**Note: DO NOT use spaces in the file name**

Personally, I like to create a `thread-groups` folder and put in all my thread groups in there:
`apache-jmeter-5.6.2\bin\thread-groups`
### Start Test
Click on your Thread Group, and then click the Green Arrow to start running the test.

You can view your results by clicking on the listeners you've added.

**NOTE**: **Don't use the GUI mode for load testing**. The GUI is only for test creation and functional testing. This is because the GUI uses a lot of memory, so it might crash while running load tests.
## CLI Mode
For load tests, use the **[CLI mode](https://jmeter.apache.org/usermanual/get-started.html#non_gui)** instead.
Open up Command Prompt, then change directory to your jmeter bin file.
For example:
`cd C:\Program Files\apache-jmeter-5.6.2\bin`
The command structure looks like this:
`jmeter -n -t {relative path to your jmx file} -l {relative path to where you want to store your result}`
For our example, we will be running this:
`jmeter -n -t ./thread-groups/Tutorial-Example.jmx -l ./log/tutorial-results.csv`
Wait for the scipt to be finished, and the results will be stored in the CSV file.
## References
[Official Docs](https://jmeter.apache.org/usermanual/get-started.html)