Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1. Introduction
2. Technologies used
3. What is this article about?
4. Installation
5. GUI overview
6. Available requests
7. Test plans and components
7.1. A Subsection
7.2. Samplers
7.3. Logic controllers
7.4. Listeners
7.5. Timers
7.6. Assertions
7.7. Configuration nodes
7.8. Pre processors
7.9. Post processors
8. Test plan elements order of execution
9. Run/Stop test plans
10. Web (HTTP) test plan
11. Database test plan tutorial
12. Junit test plan
13. Recording HTTP tests
14. JMeter Plugins
15. JMeter best practices
16. Summary
17. Download
18. Resources
1. introduction
JMeter is an application that offers several possibilities to configure and execute load,
performance and stress tests using different technologies and protocols.
It allows simulating different type of requests against all kind of databases, FTP, HTTP, HTTPS
or other kind of servers.
It is probably good to explain briefly what all these concepts mean:
Load tests: These kind of tests take the systems or applications tested to the extremes
that they were designed and required for. They are used to measure systems and applications
behavior under extreme conditions.
Performance tests: These tests are used to check how the system behaves in terms of
performance, that is, how the system responds and how is its stability for a specific workload.
Stress tests: These tests try to break or overwhelm the system by loading more resources
and taking its modules outside the limits that were designed.
Originally JMeter was designed to test web applications, but its functionality has expanded and
nowadays allows testing against almost any kind of program and can be used to perform
functional tests in your applications.
2. Technologies used
JMeter is a Java desktop application. Its UI is implemented using the Swing Java API. Due to
these two points, JMeter is multiplatform and runs in any kind of machine with a Java virtual
machine installed: Windows, Linux, Mac.
Its framework allows concurrency and the execution of several Threads and Threads Groups.
This is very useful when trying to configure load and stress tests.
It is extensible and there is a very large list of plugins available.
JMeter is part of the Apache software foundation and is completely free and open source
(http://www.apache.org/licenses/).
This article is a tutorial about how to use JMeter for developers and software engineers without
experience on JMeter.
It also provides examples and how-tos about different possible configurations and test plans. In
the next chapters we are going to see how to install JMeter and how to configure, run, store and
analyze the results of different kind of test plans.
4. Installation
You need to do the following steps in order to get JMeter installed and running in your computer:
First of all you have to install Java. You need a JRE 1.6 or above installed in your
machine. To do this, just go to the Oracle download site and install the package suitable for
your system:http://www.oracle.com/technetwork/java/javase/downloads/index.html.
Set the JAVA_HOME environment variable to point to the base directory location, where
Java is installed on your machine. For Windows users:
1 JAVA_HOME=C:\Program Files\Java\jdk1.8.0_20
Check that Java is installed in your machine by going to the command line and typing
1 java -version
01 apache-jmeter-2.9
02
03 apache-jmeter-2.9\bin
04
05 apache-jmeter-2.9\docs
06
07
08
09
10
11
12
13
14
15
apache-jmeter-2.9\extras
apache-jmeter-2.9\lib\
apache-jmeter-2.9\lib\ext
apache-jmeter-2.9\lib\junit
apache-jmeter-2.9\printable_docs
Then you can start JMeter by going to the folder C:\jmeter\apache-jmeter2.11\bin (Windows users) and starting the program jmeter.bat .
You should see the start screen of the JMeter GUI:
5. GUI overview
The JMeter GUI is very intuitive and easy to use, common menus for file handling like new,
open, save, save as etc. and specific menus for starting and stopping test plans and configuring
them are available. Every test plan, thread group and test plan node (we will see these more in
detail in the next chapters) offer different context menu options by clicking the mouse right
button.
It is also possible to change the language of the UI and a big bunch of languages are available.
As we said, the GUI is very intuitive and easy to use and offers for every menu and action very
understandable tool tips. This is one of the reasons, apart from its quality, why JMeter is so
broadly used, because it is really easy to understand and learn how to work with it.
6. Available requests
JMeter offers test configurations for almost any kind of system, but in general, following
protocols are covered out of the box:
Web: HTTP, HTTPS sites web 1.0 web 2.0 (ajax, flex and flex-ws-amf): we will see
afterwards how to test a potential web page and its behavior.
Directory: LDAP.
FTP Service.
7.1 ThreadGroup
A thread group is basically a combination of different test plan elements. It is the root of a test
plan and it controls the basic central parameters.
In order to create a test plan you may have to create at first a thread group and configure its
number of threads, the ramp-up period, the loop counts and the behavior in case or error:
Number of threads: The number of threads that are going to be used to execute the test
plan, very important to configure load and stress tests.
Ramp-up period: Time that JMeter will need to start all threads.
Loop count: Number of iterations, that is the amount of times that the test is going to be
executed.
Error behavior: What to do in case of error: Stop current thread, stop the whole test,
continue
A Thread Group has also the start and end time configuration options. By clicking the checkbox
Scheduler a new section with the schedule parameters will appear and you can configure the
start and end time of your test.
Once this is configured you can start adding other test plan elements to your Thread group like
samplers, listener and timers. We are going to explain all these in the next chapters.
7.2 Samplers
Samplers are used for sending requests to different kind of servers. They are the basic element of
every test plan and everything works around them: they execute requests (based on the
configuration provided) and these requests produce one or more responses that are analyzed
afterwards.
Here is a list of the Samplers available in JMeter (we are going to see some of them in this
tutorial):
AJP sampler
BSF sampler
Debug sampler
FTP sampler
HTTP sampler
Java sampler
JDBC sampler
JSR223 sampler
JUnit sampler
Mail Reader
MongoDB sampler
OS process sampler
SMTP sampler
SOAP
TCP samplers
Test action
As we can see in the list above, there are a lot of different types of samplers; this list is not
complete since there are several samplers implemented in different JMeter plugins. The
configuration of each sampler depends on the request that it executes, that means that some
samplers have things in common but others are completely different because of the nature of
their requests.
Simple Controller
Loop Controller
Interleave Controller
Random Controller
Throughput Controller
Runtime Controller
If Controller
While Controller
Switch Controller
ForEach Controller
Module Controller
Include Controller
Transaction Controller
Recording Controller
7.4 Listeners
Listeners provide different ways to view the results produced by a Sampler requests. Listeners
parse results in form of tables, trees or plain log files.
They can be added anywhere in a test plan, but they will only parse and collect result data from
the samplers at their level or in the levels bellow.
These are the available listeners in JMeter:
Graph Results
Spline Visualizer
Assertion Results
Aggregate Report
Monitor Results
Aggregate Graph
Mailer Visualizer
BeanShell Listener
Summary Report
7.5 Timers
You can define the time period that you want to wait between requests using timers. If you do not
specify any, JMeter will execute the next request immediately after the current one is finished,
without any waiting time.
Following timers are available in JMeter:
Constant Timer
Synchronizing Timer
JSR223 Time
BeanShell Time
BSF Time
7.6 Assertions
Assertions confirm the validity of the test plan by validating the response produced by a Sampler
request. Basically assertions are similar to unit test assertions and check the quality of the tested
application response. You can configure what kind of assertions is active for every test plan.
Here is a list of available assertions in JMeter:
BSF Assertion
Compare Assertion
JSR223 Assertion
Response Assertion
Duration Assertion
Size Assertion
XML Assertion
BeanShell Assertion
MD5Hex Assertion
HTML Assertion
XPath Assertion
Counter
Keystore Configuration
Random Variable
User Parameters
JDBC PreProcessor
JSR223 PreProcessor
BeanShell PreProcessor
BSF PreProcessor
XPath Extractor
JSR223 PostProcessor
JDBC PostProcessor
BSF PostProcessor
CSS/JQuery Extractor
BeanShell PostProcessor
Debug PostProcessor
"Play"
button:
It is possible to start a test and ignore all the pauses by clicking in the button
"Stop"
button:
"Play no pauses"
It is also possible to disable test plans for execution. To do this you just need to toogle the
status of the test plan:
As you can see in the screen capture above, the disabled plans are rendered with grey color and
they cannot be executed but they can be modified or reconfigured.
In this chapter we are going to see how to create a plan to test an specific web page via HTTP.
For that purpose i will use the http://www.wikipedia.org site.
So enough theory, now we are going to see how to configure an HTTP request test plan.
In this step you need to create a Thread group in charge of executing all the components of the
test and configure its main properties: number of threads, ramp up period in seconds and number
of iterations.
Context Menu over Test Plan -> Add -> Thread ->ThreadGroup
you can also specify the action you want to take in case of error (continue, stop, stop current
Thread)
This is needed to be able to see the results afterwards; there are several possibilities as we saw
before in this tutorial, for our HTTP Request test plan we are going to use a View Results Tree:
Add Listener -> View Results Tree
For our example, we do not change anything there and leave all the configuration properties with
the default values.
We can see that all the requests have been done as expected and all of them provide meaningful
responses, so it seems that the web page that we are testing works fine (if this is the expected
behavior). We can play around with the results and check all the returned data.
We have already configured a test plan that sends a bunch or requests to a given server and
parses the responses. We are going to see now how to use other type of test components like
Timers and Assertions.
Add a timer
In order to add a Timer we just right click on the test plan and add a timer:
Add Timer->Constant Timer
and we configure it with 500 miliseconds. Every request will wait 500 ms after the last one is
finished.
On the test plan, right click and add a duration assertion, we configure it to assert false if the
response takes longer than 100 ms, and we configure it for the main sample only:
Add assertion->Duration assertion
If we re run the test plan (after saving) we will see that we have some issues with this assertion:
Obvioulsy this happens because we configure the duration assertion only with 100 ms, if we
change this figure to 2000 ms almost all requests will be served on time.
If we run the test we will see that the response is always larger than that, in case of an error
response the size would be, probably, smaller and our assertion will fail.
Now we are going to see how to configure, run and analyze the results of a test against a MySQL
Database. This example is about MySQL but it can be done using any other kind of DB like
Oracle, MongoDB or others.
Install MySQL
If you do not have MySQL installed in your computer, you can download it
from http://dev.mysql.com/downloads/ and install the MySQL server, it is very easy.
Start MySQL
Start the DB server so that you can make queries against it.
Create database
You can create a database as you want, here is just an example of a very simple one:
01 create database jmeter;
02
03 use jmeter;
04
05 create table jmeter_stuff(id int, name varchar(50), description
varchar(50));
06
insert into jmeter_stuff(id, name, description)VALUES(1, "dani", "the
07
boss");
08
09
10
11
Do the same actions as in the chapter before to create a test Plan using a new Thread Group, a
new configuration element of the type JDBC configuration and a new request (sampler) of the
type JDBC, add also a listener to parse and view the results in the same way as we did in the
example before.
The only difference is the type of the sampler, in this case JDBC Sampler.
JDBC Sampler
Give a meaningful name to the Variable Bound to Pool and write some SQL statement:
1 select * from jmeter_stuff;
2
3
4
5
6
Database URl=jdbc:mysql://localhost:3306/jmeter
JDBC Driver class=com.mysql.jdbc.Driver
username=
password=
You can verify and check the output in the same way as in the HTTP request test plan, you can
also add preprocessors, post processors, assertions or any other kind of element that you may
need.
First of all you need to create a Junit test like the following one:
01 public class JMeterTest
02 {
03
04
05
06
07
08
09
public JMeterTest()
{
// just for testing purposes
System.out.println( "calling the constructor" );
}
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
@Before
public void setUp() throws Exception
{
// just for testing purposes
System.out.println( "calling setup" );
}
@After
public void tearDown() throws Exception
{
// just for testing purposes
System.out.println( "calling tearDown" );
}
@Test
public void testMe()
{
This test mainly contains a couple of assertions in order to check how JMeter can use them, it is
not the purpose of this tutorial to explain unit testing or JUnit in detail.
Or you can export your project as JAR file including the bytecode and generated files directly in
Eclipse or your favorite IDE.
Create a test plan as we saw before and add a sampler of the type JUnit request: Add Sampler>Junit Request and configure it in order to execute the methods that you want from the test that
you just created above.
In our case we are going to execute JUnit 4 based methods, but you can also do this using JUnit
3 by selecting the check box for this purpose.
Here we can see the results of the JUnit test that we have just created:
As we can see in the screenshot above, all our tests (1 test, 10 loops) failed. This is the expected
behaviour since we wanted our test to fail. Actually the unit test that we just wrote has no
functional meaning and it is useless. Its purpose is just to show how to configure JMeter to use
these kind of unit tests.
The stuff explained in this chapter may be very helpful to test functional and business logic of
application using JMeter with all the benefits that this application provides, it is also very
interesting because it makes possible to combine all the Java language advantages with the
multithreating capabilites of JMeter.
Go to your Firefox network settings and select the manual proxy option and set as server
localhost and port 8080 (actually this deepens on your JMeter configuration). After that, check
the option Use this proxy server for all protocols.
We add a new Thread Group and we give a name to it. We configure the Thread Group to have
50 threads, 10 seconds as ramp-up period and number of loops equals 1.
On the Thread Group that we just created, we add a new Config Element and we select HTTP
Request Defaults.
You should write here the server name that you want to test.
You should now that the workbench has to be stored independtly from your test plan. Saving
your test plan does not save the workbench.
Configure the Recorder as follows:
Add timer
If you want you can add a timer (constant) to your recorder, this timer will be used by each
HTTP request that is recorded.
Start recording
By clicking on the start button of the recorder, you will start the JMeter proxy server.
If you go to a web page in order to make an example HTTP request, for example go
to http://www.oviedin.com using Firefox (after configuring it as explained in the first step of this
chapter) you will see that different entries appear under the Recording Controller in your test
plan.
These records are actually HTTP requests that have been done while querying the web page
mentioned before. Only records included in the filter configured in the Test Script Recorded will
be stored. They can be reconfigured and used afterwards in your test plans.
Before this article finishes we are going to write down a couple of very useful tricks and best
practices:
Although the JMeter UI is a very useful and intuitive tool for configuring and creating
different test plans, experience users would like to use the non-GUI mode for executing them
and storing their results.
You can do this by typing:
jmeter -n -t test.jmx -l test.jtl.
Assuming test is the test that you want to execute. You have to provide the complete path where
your test is stored.
Listeners are good to parse results, but they are also resource intensive and consume a lot
of memory so it is good to use as few Listeners as possible in your configurations. The flag -l
delete them all and it is recommended when listeners are not needed.
Check the flag View only errors in the results tree view, probably you are only
interested in checking what errors occurred during your tests.
Use variables and loops in the same sampler instead of configuring several similar
samples only differentiated by the variables and parameters that they are using.
When creating Junit test plans it is recommended to provide meaningful error and
assertion messages so that the JMeter output is as understandable as possible, this is a general
recommendation when working with unit tests that applies completely in this case.
Using Stop (Control + '.') . This stops the threads immediately if possible.
Using Shutdown (Control + ',') . This requests the threads to stop at the end of any current
work. Other tool tips are available at https://wiki.apache.org/jmeter/JMeterShortcuts.
16. Summary
So that is all.
We saw how to install JMeter and how to configure it for executing different kind of tests like
HTTP requests, tests against databases and functional tests against Junit ones. There are many
others kind of tests and possibilities offered with JMeter that are not covered in this tutorial. The
objective of this tutorial is to give a whole description of the application and to show how to
configure your first test plans.
We also explained the main parts of the JMeter UI and how to use it and also the test plan
elements that come with JMeter out of the box.
In the last chapter we mentioned the possibility to expand JMeter with different Plugins; this is a
very interesting point for experience users with advanced needs.