0% found this document useful (0 votes)
8 views35 pages

Session 2

The document provides a comprehensive guide on performance testing using JMeter, detailing its GUI overview, test plans, and various components such as ThreadGroups, Samplers, Logic Controllers, Listeners, Timers, Assertions, and Configuration Nodes. It includes practical scenarios demonstrating the creation of test plans and best practices for efficient usage of JMeter. Additionally, it emphasizes the importance of resource management and effective error handling during performance testing.

Uploaded by

Nguyễn Lộc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views35 pages

Session 2

The document provides a comprehensive guide on performance testing using JMeter, detailing its GUI overview, test plans, and various components such as ThreadGroups, Samplers, Logic Controllers, Listeners, Timers, Assertions, and Configuration Nodes. It includes practical scenarios demonstrating the creation of test plans and best practices for efficient usage of JMeter. Additionally, it emphasizes the importance of resource management and effective error handling during performance testing.

Uploaded by

Nguyễn Lộc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 35

Performance testing sharing

Contents
I. GUI overview.....................................................................................................................................1
II. Test plans and components............................................................................................................2
1. ThreadGroup.................................................................................................................................2
2. Samplers........................................................................................................................................3
3. Logic controllers............................................................................................................................4
4. Listeners.........................................................................................................................................5
5. Timers.............................................................................................................................................5
6. Assertions......................................................................................................................................6
7. Configuration nodes......................................................................................................................6
8. Pre processors..............................................................................................................................7
9. Post processors.............................................................................................................................8
III. Practice Scenario..........................................................................................................................8
1. Scenario 1: Hard code to create a simple test..........................................................................8
2. Scenario 2: E...............................................................................................................................19
3. Scenario 3: Timer........................................................................................................................21
3.1. Constant Timer....................................................................................................................21
3.2. Uniform Random Timer......................................................................................................23
4. Scenario 4: CSV data set...........................................................................................................24
5. Scenario 5: Condition controller................................................................................................29
5.1. Loop controller.....................................................................................................................29
5.2. While controller....................................................................................................................31
6. Scenario 6: Pre-Processor.........................................................................................................33
6.1. User Paramerters................................................................................................................33
IV. JMeter best practices.................................................................................................................35

1
Performance testing sharing

I. GUI overview

II. Test plans and components


Basically, using JMeter consists of the creation, configuration and execution of test
plans and the analysis of their results. Test plans are sets of requests against local or
remote servers (or clients) configured to run by following specific instructions.
In the configuration of a test plan you can specify several input and output parameters
and you can configure the basic conditions that should be met so the test plan is
successful or not.
JMeter test plans are composed of different components. Here is a list of the most
important ones with instructions about how you can add them using the JMeter UI and
what their purpose is:
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:

2
Performance testing sharing

• 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.
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):
• Access log sampler
• AJP sampler
• Bean shell sampler
• BSF sampler
• Debug sampler
• FTP sampler
• HTTP sampler
• Java sampler
• JDBC sampler
• JMS (several) samplers
• JSR223 sampler

3
Performance testing sharing

• JUnit sampler
• LDAP (several) samplers
• 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 others 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.
3. Logic controllers
Logic controllers are elements that allow you to configure the order of execution of
different samplers inside a Thread group. This list contains all available logic controllers
in JMeter:
• Simple Controller
• Loop Controller
• Once Only Controller
• Interleave Controller
• Random Controller
• Random Order Controller
• Throughput Controller
• Runtime Controller
• If Controller
• While Controller
• Switch Controller
• ForEach Controller
• Module Controller

4
Performance testing sharing

• Include Controller
• Transaction Controller
• Recording Controller
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:
• Sample Result Save Configuration
• Graph Full Results
• Graph Results
• Spline Visualizer
• Assertion Results
• View Results Tree
• Aggregate Report
• View Results in Table
• Simple Data Writer
• Monitor Results
• Distribution Graph (alpha)
• Aggregate Graph
• Mailer Visualizer
• BeanShell Listener
• Summary Report
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
• Gaussian Random Timer

5
Performance testing sharing

• Uniform Random Timer


• Constant Throughput Timer
• Synchronizing Timer
• JSR223 Time
• BeanShell Time
• BSF Time
• Poisson Random Time
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:
• Bean shell Assertion
• BSF Assertion
• Compare Assertion
• JSR223 Assertion
• Response Assertion
• Duration Assertion
• Size Assertion
• XML Assertion
• BeanShell Assertion
• MD5Hex Assertion
• HTML Assertion
• XPath Assertion
• XML Schema Assertion
7. Configuration nodes
You can pass different parameters to the sampler requests by using configuration
elements. They provide a way to create variables (different and dynamically) that can be
used by the samplers afterwards. They are executed at the beginning of the node they

6
Performance testing sharing

belong to, before the samplers are executed, that is why the samplers can rely on these
variables.
Here is a list of all the configuration nodes that can be used in JMeter:
• Counter
• CSV Data Set Config
• FTP Request Defaults
• HTTP Authorization Manager
• HTTP Cache Manager
• HTTP Cookie Manager
• HTTP Proxy Server
• HTTP Request Defaults
• HTTP Header Manager
• Java Request Defaults
• Keystore Configuration
• JDBC Connection Configuration
• Login Config Element
• LDAP Request Defaults
• LDAP Extended Request Defaults
• TCP Sampler Config
• User Defined Variables
• Simple Config Element
• Random Variable
8. Pre processors
Pre processors are elements (actions, assertions or basically whatever) that are going
to happen before a sampler is executed. They can be used to extract variables from a
response that can be used in the sampler afterwards via configuration elements.
These are the elements that can be used as pre processors:
• HTML Link Parser
• HTTP URL Re-writing Modifier
• HTTP User Parameter Modifier
• User Parameters

7
Performance testing sharing

• JDBC PreProcessor
• JSR223 PreProcessor
• RegEx User Parameters
• BeanShell PreProcessor
• BSF PreProcessor
9. Post processors
A post processor is basically an element that is executed after a sampler execution
finishes. It can be used to parse the response data and extract values that can be used
afterwards.
These elements can be used as post processors:
• Regular Expression Extractor
• XPath Extractor
• Result Status Action Handler
• JSR223 PostProcessor
• JDBC PostProcessor
• BSF PostProcessor
• CSS/JQuery Extractor
• BeanShell PostProcessor

8
Performance testing sharing

III. Practice Scenario


1. Scenario 1: Hard code to create a simple test

9
Performance testing sharing

10
Performance testing sharing

11
Performance testing sharing

12
Performance testing sharing

13
Performance testing sharing

14
Performance testing sharing

15
Performance testing sharing

16
Performance testing sharing

17
Performance testing sharing

18
Performance testing sharing

2. Scenario 2: Interaction flow

19
Performance testing sharing

"Auth_token: (.*?)"

{"cookie":"${access_token}","flag":true}

20
Performance testing sharing

3. Scenario 3: Timer
3.1. Constant Timer

21
Performance testing sharing

22
Performance testing sharing

3.2. Uniform Random Timer

23
Performance testing sharing

4. Scenario 4: CSV data set

24
Performance testing sharing

25
Performance testing sharing

26
Performance testing sharing

27
Performance testing sharing

28
Performance testing sharing

5. Scenario 5: Condition controller


5.1. Loop controller

29
Performance testing sharing

30
Performance testing sharing

5.2. While controller

31
Performance testing sharing

32
Performance testing sharing

6. Scenario 6: Pre-Processor
6.1. User Paramerters

33
Performance testing sharing

34
Performance testing sharing

IV. JMeter best practices


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.

35

You might also like