3. Elements of a Test Plan
https://jmeter.apache.org/usermanual/test_plan.html
This section describes the different parts of a test plan.
A minimal test will consist of the Test Plan, a Thread Group and one or more Samplers.
3.0 Test Plan
The Test Plan object has a checkbox called "Functional Testing". If selected, it will cause JMeter to record the data returned from the server for each sample. If you have selected a file in your test listeners, this data will be written to file. This can be useful if you are doing a small run to ensure that JMeter is configured correctly, and that your server is returning the expected results. The consequence is that the file will grow huge quickly, and JMeter's performance will suffer. This option should be off if you are doing stress-testing (it is off by default).
If you are not recording the data to file, this option makes no difference.
You can also use the Configuration button on a listener to decide what fields to save.
3.1 Thread Group
Thread group elements are the beginning points of any test plan.
All controllers and samplers must be under a thread group.
Other elements, e.g. Listeners, may be placed directly under the test plan, in which case they will apply to all the thread groups.
As the name implies, the thread group element controls the number of threads JMeter will use to execute your test.
The controls for a thread group allow you to:
- Set the number of threads
- Set the ramp-up period 过渡时期
- Set the number of times to execute the test
Each thread will execute the test plan in its entirety and completely independently of other test threads. Multiple threads are used to simulate concurrent connections to your server application.
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.
Ramp-up needs to be long enough to avoid too large a work-load at the start of a test, and short enough that the last threads start running before the first ones finish (unless one wants that to happen).
Start with Ramp-up = number of threads and adjust up or down as needed.
By default, the thread group is configured to loop once through its elements.
Thread Group also provides a scheduler.
Click the checkbox at the bottom of the Thread Group panel to enable/disable extra fields in which you can enter the duration of test, the startup delay, the start and end times of the run.
You can configure Duration (seconds) and Startup Delay (seconds) to control the duration of each thread group and the after how much seconds it starts.
When the test is started, JMeter will wait Startup Delay (seconds) before starting the Threads of the Thread Group and run for the configured Duration (seconds) time. Note those 2 options override the Start time and End time.
Alternatively (although not recommended as not very flexible) you can use the two other fields Start time and End time.
When the test is started, JMeter will wait if necessary until the start-time has been reached.
At the end of each cycle, JMeter checks if the end-time has been reached, and if so, the run is stopped, otherwise the test is allowed to continue until the iteration limit is reached.
3.2 Controllers
JMeter has two types of Controllers: Samplers and Logical Controllers. These drive the processing of a test.
Samplers tell JMeter to send requests to a server.
For example, add an HTTP Request Sampler if you want JMeter to send an HTTP request.
You can also customize a request by adding one or more Configuration Elements to a Sampler.
For more information, see Samplers.
Logical Controllers let you customize the logic that JMeter uses to decide when to send requests.
For example, you can add an Interleave Logic Controller to alternate between two HTTP Request Samplers.
For more information, see Logical Controllers.
3.2.1 Samplers
Samplers tell JMeter to send requests to a server and wait for a response.
They are processed in the order they appear in the tree.
Controllers can be used to modify the number of repetitions of a sampler.
JMeter samplers include:
- FTP Request
- HTTP Request (can be used for SOAP or REST Webservice also)
- JDBC Request
- Java object request
- JMS request
- JUnit Test request
- LDAP Request
- Mail request
- OS Process request
- TCP request
Each sampler has several properties you can set. You can further customize a sampler by adding one or more Configuration Elements to the Test Plan.
If you are going to send multiple requests of the same type (for example, HTTP Request) to the same server, consider using a Defaults Configuration Element. Each controller has one or more Defaults elements (see below).
Remember to add a Listener to your test plan to view and/or store the results of your requests to disk.
If you are interested in having JMeter perform basic validation on the response of your request, add an Assertion to the sampler.
For example, in stress testing a web application, the server may return a successful "HTTP Response" code, but the page may have errors on it or may be missing sections. You could add assertions to check for certain HTML tags, common error strings, and so on. JMeter lets you create these assertions using regular expressions.
3.2.2 Logic Controllers
Logic Controllers let you customize the logic that JMeter uses to decide when to send requests.
Logic Controllers can change the order of requests coming from their child elements.
They can modify the requests themselves, cause JMeter to repeat requests, etc.
To understand the effect of Logic Controllers on a test plan, consider the following test tree:
- Test Plan
- Thread Group
- Once Only Controller
- Login Request (an HTTP Request)
- Load Search Page (HTTP Sampler)
- Interleave Controller
- Search "A" (HTTP Sampler)
- Search "B" (HTTP Sampler)
- HTTP default request (Configuration Element)
- HTTP default request (Configuration Element)
- Cookie Manager (Configuration Element)
The first thing about this test is that the login request will be executed only the first time through. Subsequent iterations will skip it. This is due to the effects of the Once Only Controller.
After the login, the next Sampler loads the search page (imagine a web application where the user logs in, and then goes to a search page to do a search). This is just a simple request, not filtered through any Logic Controller.
After loading the search page, we want to do a search.
Actually, we want to do two different searches.
However, we want to re-load the search page itself between each search.
We could do this by having 4 simple HTTP request elements (load search, search "A", load search, search "B").
Instead, we use the Interleave Controller which passes on one child request each time through the test.
It keeps the ordering (i.e. it doesn't pass one on at random, but "remembers" its place) of its child elements.
Interleaving交错 2 child requests may be overkill, but there could easily have been 8, or 20 child requests.
Note the HTTP Request Defaults that belongs to the Interleave Controller.
Imagine that "Search A" and "Search B" share the same PATH info (an HTTP request specification includes domain, port, method, protocol, path, and arguments, plus other optional items).
This makes sense - both are search requests, hitting the same back-end search engine (a servlet or cgi-script, let's say).
Rather than configure both HTTP Samplers with the same information in their PATH field, we can abstract that information out to a single Configuration Element.
When the Interleave Controller "passes on" requests from "Search A" or "Search B", it will fill in the blanks with values from the HTTP default request Configuration Element.
So, we leave the PATH field blank for those requests, and put that information into the Configuration Element.
In this case, this is a minor benefit at best, but it demonstrates the feature.
The next element in the tree is another HTTP default request, this time added to the Thread Group itself.
The Thread Group has a built-in Logic Controller, and thus, it uses this Configuration Element exactly as described above.
It fills in the blanks of any Request that passes through.
It is extremely useful in web testing to leave the DOMAIN field blank in all your HTTP Sampler elements, and instead, put that information into an HTTP default request element, added to the Thread Group.
By doing so, you can test your application on a different server simply by changing one field in your Test Plan. Otherwise, you'd have to edit each and every Sampler.
The last element is a HTTP Cookie Manager. A Cookie Manager should be added to all web tests - otherwise JMeter will ignore cookies.
By adding it at the Thread Group level, we ensure that all HTTP requests will share the same cookies.
Logic Controllers can be combined to achieve various results. See the list of built-in Logic Controllers.
3.2.3 Test Fragments
The Test Fragment element is a special type of controller that exists on the Test Plan tree at the same level as the Thread Group element.
It is distinguished from a Thread Group in that it is not executed unless it is referenced by either a Module Controller or an Include_Controller.
This element is purely for code re-use within Test Plans
3.3 Listeners
Listeners provide access to the information JMeter gathers about the test cases while JMeter runs.
The Graph Results listener plots绘图 the response times on a graph.
The "View Results Tree" Listener shows details of sampler requests and responses, and can display basic HTML and XML representations of the response.
Other listeners provide summary or aggregation information.
Additionally, listeners can direct the data to a file for later use.
Every listener in JMeter provides a field to indicate the file to store data to.
There is also a Configuration button which can be used to choose which fields to save, and whether to use CSV or XML format.
Listeners can be added anywhere in the test, including directly under the test plan.
They will collect data only from elements at or below their level.
There are several listeners that come with JMeter.
3.4 Timers
By default, a JMeter thread executes samplers in sequence without pausing.
We recommend that you specify a delay by adding one of the available timers to your Thread Group.
If you do not add a delay, JMeter could overwhelm淹没 your server by making too many requests in a very short amount of time.
A timer will cause JMeter to delay a certain amount of time before each sampler which is in its scope.
If you choose to add more than one timer to a Thread Group, JMeter takes the sum of the timers and pauses for that amount of time before executing the samplers to which the timers apply.
Timers can be added as children of samplers or controllers in order to restrict the samplers to which they are applied.
To provide a pause at a single place in a test plan, one can use the Test Action Sampler.
3.5 Assertions
Assertions allow you to assert facts about responses received from the server being tested. Using an assertion, you can essentially "test" that your application is returning the results you expect it to.
For instance, you can assert that the response to a query will contain some particular text.
The text you specify can be a Perl-style regular expression, and you can indicate that the response is to contain the text, or that it should match the whole response.
You can add an assertion to any Sampler.
For example, you can add an assertion to a HTTP Request that checks for the text, "</HTML>".
JMeter will then check that the text is present in the HTTP response.
If JMeter cannot find the text, then it will mark this as a failed request.
To view assertion results, add an Assertion Listener to the Thread Group.
Failed Assertions will also show up in the Tree View and Table Listeners, and will count towards the error %age for example in the Aggregate and Summary reports.
3.6 Configuration Elements
A configuration element works closely with a Sampler. Although it does not send requests (except for HTTP(S) Test Script Recorder), it can add to or modify requests.
A configuration element is accessible from only inside the tree branch where you place the element.
For example, if you place an HTTP Cookie Manager inside a Simple Logic Controller, the Cookie Manager will only be accessible to HTTP Request Controllers you place inside the Simple Logic Controller (see figure 1).
The Cookie Manager is accessible to the HTTP requests "Web Page 1" and "Web Page 2", but not "Web Page 3".
Also, a configuration element inside a tree branch has higher precedence优先 than the same element in a "parent" branch.
For example, we defined two HTTP Request Defaults elements, "Web Defaults 1" and "Web Defaults 2".
Since we placed "Web Defaults 1" inside a Loop Controller, only "Web Page 2" can access it.
The other HTTP requests will use "Web Defaults 2", since we placed it in the Thread Group (the "parent" of all other branches).
Figure 1 - Test Plan Showing Accessibility of Configuration Elements
3.7 Pre-Processor Elements¶
A Pre-Processor executes some action prior to a Sampler Request being made.
If a Pre-Processor is attached to a Sampler element, then it will execute just prior to that sampler element running.
A Pre-Processor is most often used to modify the settings of a Sample Request just before it runs, or to update variables that aren't extracted from response text.
See the scoping rules for more details on when Pre-Processors are executed.
3.8 Post-Processor Elements
A Post-Processor executes some action after a Sampler Request has been made.
If a Post-Processor is attached to a Sampler element, then it will execute just after that sampler element runs.
A Post-Processor is most often used to process the response data, often to extract values from it.
See the scoping rules for more details on when Post-Processors are executed.
3.9 Execution order
- Configuration elements
- Pre-Processors
- Timers
- Sampler
- Post-Processors (unless SampleResult is null)
- Assertions (unless SampleResult is null)
- Listeners (unless SampleResult is null)
For example, in the following test plan:
- Controller
- Post-Processor 1
- Sampler 1
- Sampler 2
- Timer 1
- Assertion 1
- Pre-Processor 1
- Timer 2
- Post-Processor 2
The order of execution would be: timer,processor,assertion会被重复执行
Pre-Processor 1
Timer 1
Timer 2
Sampler 1
Post-Processor 1
Post-Processor 2
Assertion 1 Pre-Processor 1
Timer 1
Timer 2
Sampler 2
Post-Processor 1
Post-Processor 2
Assertion 1
3.10 Scoping Rules
The JMeter test tree contains elements that are both hierarchical and ordered.
Some elements in the test trees are strictly hierarchical (Listeners, Config Elements, Post-Processors, Pre-Processors, Assertions, Timers), and some are primarily ordered (controllers, samplers).
When you create your test plan, you will create an ordered list of sample request (via Samplers) that represent a set of steps to be executed.
These requests are often organized within controllers that are also ordered. Given the following test tree:
Example test tree
The order of requests will be, One, Two, Three, Four.
Some controllers affect the order of their subelements, and you can read about these specific controllers in the component reference.
Other elements are hierarchical.
An Assertion, for instance, is hierarchical in the test tree.
If its parent is a request, then it is applied to that request.
If its parent is a Controller, then it affects all requests that are descendants of that Controller. In the following test tree:
Hierarchy example
Assertion #1 is applied only to Request One, while Assertion #2 is applied to Requests Two and Three.
Another example, this time using Timers:
complex example
In this example, the requests are named to reflect the order in which they will be executed.
Timer #1 will apply to Requests Two, Three, and Four (notice how order is irrelevant for hierarchical elements).
Assertion #1 will apply only to Request Three.
Timer #2 will affect all the requests.
Hopefully these examples make it clear how configuration (hierarchical) elements are applied.
If you imagine each Request being passed up the tree branches, to its parent, then to its parent's parent, etc., and each time collecting all the configuration elements of that parent, then you will see how it works.
3. Elements of a Test Plan的更多相关文章
- JMeter 一:Elements of a Test Plan
参考:http://jmeter.apache.org/usermanual/test_plan.html 最小测试集包括:Test Plan,一个Thread Group,以及一个或多个Sample ...
- Building An Effective Marketing Plan
“New ideas are a dime a dozen,” observes Arthur R. Kydd, “and so are new products and new technologi ...
- Jmeter测试计划中的元素
测试计划中的元素(elements of a test plan) 本节描述测试计划不同的部分. 最小测试将包括测试计划.线程组和一个或多个采样器. 1 测试计划(Test Plan) 测试计划对象有 ...
- Setup and Teardown Thread Group in Jmeter
setup和teardown有点类似于每个测试用例开始和结束时要做的动作 A Thread Group is the starting point of any Jmeter Test Plan. A ...
- Apache JMeter
https://en.wikipedia.org/wiki/Apache_JMeter Apache JMeter 是 Apache 的一个项目,它是一个负载测试工具可以用于进行各种服务器的性能测试分 ...
- JMeter入门介绍
目录 概述 下载&安装 实战JMetetr 测试计划简述 准备测试计划 编写测试计划 录制测试脚本 执行性能测试 单机测试 分布式测试 分析测试报告 APDEX 响应时间和吞吐量统计 测试结果 ...
- Oracle Quality --- Setup Collection Element and Collection Plan
Responsibility: Quality, Vision Enterprises 第一步: 创建 Collection Elements setup > collection elemen ...
- JMeter Building a Database Test Plan
Building a Database Test Plan In this section, you will learn how to create a basic Test Planto test ...
- 【转】The most comprehensive Data Science learning plan for 2017
I joined Analytics Vidhya as an intern last summer. I had no clue what was in store for me. I had be ...
随机推荐
- css 文字样式
Gradient 3D text 代码区域 /*css */ body { background-color: #272727; } h1 { font-family: "Arial&quo ...
- JavaScript中直接量和变量
标题 1.直接量 顾名思义,可以直接拿来使用的量.那哪些是直接量呢?数据类型又有很多种,因为不同类型的数据处理方式是不同的,所以数据要分类型 基本类型 1.1 String字符串 用单引号或双引号引起 ...
- 20155228 2016-2017-2 《Java程序设计》第5周学习总结
20155228 2016-2017-2 <Java程序设计>第5周学习总结 教材学习内容总结 异常处理 try-catch语法:JVM执行try区块中的代码,如果发生错误就会跳到catc ...
- arm cortex-m0plus源码学习(二)AMBA3.0_ AHBLite
1. AMBA总线概述 AMBA2.0 以上版本都是基于单沿时钟.单向信号线的协议[1]. 现在市场上大部分的基于 AMBA 架构的 SoC 产品, 系统总线采用 AHB, 外部总线采用 APB.系统 ...
- restful的特点
1. 资源(Resources) REST的名称”表现层状态转化”中,省略了主语.”表现层”其实指的是”资源”(Resources)的”表现层”. 所谓”资源”,就是网络 ...
- flask模板的基本用法(定界符、模板语法、渲染模板),模板辅助工具(上下文、全局对象、过滤器、测试器、模板环境对象)
flask模板 在动态web程序中,视图函数返回的HTML数据往往需要根据相应的变量(比如查询参数)动态生成. 当HTML代码保存到单独的文件中时,我们没法再使用字符串格式化或拼接字符串的当时在HTM ...
- python小练习:读入一个考试得分,判断这个分数是哪个等级,并输出,考虑异常场景
读入一个考试得分,判断这个分数是哪个等级,并输出. 等级:>=90 优 ,>=80且小于90 良,>=70 且小于80,中,>=60且<70及格 <60 不及格 ...
- 三角形垂点坐标js算法(三点定圆求圆心)
已知平面三点坐标A(x1, y1).B(x2, y2).C(x3, y3),三点定圆也就是三角形的中垂线交点, //平面三点定位算法 function locate(x1, y1, x2, y2, x ...
- echart中间显示固定的字
- Java学习技术分享:Java中的原子操作
学习java需要有一套完整的学习线路,需要有条理性,当下学习java已经有一段时间了,由当初的懵逼状态逐渐好转,也逐渐养成了写技术学习笔记的习惯,今天总结了一下java中的原子操作. 1.Java中的 ...