Jmeter 初识二 TestFragment使用记载

TestFragment 顾名思义,碎片化的处理方式 。 它通常和module 一起使用。

官方介绍:http://jmeter.apache.org/usermanual/test_plan.html#logic_controller

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.

So , 因为登陆获取token的操作 , 以及后期 获取处理task的操作 比较频繁,所以我们使用了TestFragment , moduleController ,Include_Controller 组合使用。

以在登陆操作中的使用为例:

S1: 创建一个与threadGroup 同级别的Testfragment ,进行正常的获取token的操作,创建 请求 ,填入参数 ,获取token。保存成一个.jmx文件。

S2: 在另一个Jmeter脚本文件中使用TestFragment。

    --> 1.create a test fragment then add a include controller , 将S1 中生成的.jmx文件的路径填入testplan filename 的输入框。

关于Include Controller ,官方介绍: 

Include Controller

The include controller is designed to use an external JMX file. To use it, create a Test Fragment underneath the Test Plan and add any desired samplers, controllers etc. below it. Then save the Test Plan. The file is now ready to be included as part of other Test Plans.

For convenience, a Thread Group can also be added in the external JMX file for debugging purposes. A Module Controller can be used to reference the Test Fragment. The Thread Group will be ignored during the include process.

S3: 调用S1 中建立的testFragment。

   利用Module Controller , 调用该test plan中的 test Fragment的程序。

Module Controller 官方介绍:

Module Controller

The Module Controller provides a mechanism for substituting test plan fragments into the current test plan at run-time.

A test plan fragment consists of a Controller and all the test elements (samplers etc.) contained in it. The fragment can be located in any Thread Group. If the fragment is located in a Thread Group, then its Controller can be disabled to prevent the fragment being run except by the Module Controller. Or you can store the fragments in a dummy Thread Group, and disable the entire Thread Group.

There can be multiple fragments, each with a different series of samplers under them. The module controller can then be used to easily switch between these multiple test cases simply by choosing the appropriate controller in its drop down box. This provides convenience for running many alternate test plans quickly and easily.

此处用到的Only once Controller , 因为token只需获取一次在失效前可一致持续性使用,所以是用 Only once controller。

Once Only Controller

The Once Only Logic Controller tells JMeter to process the controller(s) inside it only once per Thread, and pass over any requests under it during further iterations through the test plan.

The Once Only Controller will now execute always during the first iteration of any looping parent controller. Thus, if the Once Only Controller is placed under a Loop Controller specified to loop 5 times, then the Once Only Controller will execute only on the first iteration through the Loop Controller (i.e. every 5 times).

Note this means the Once Only Controller will still behave as previously expected if put under a Thread Group (runs only once per test per Thread), but now the user has more flexibility in the use of the Once Only Controller.

For testing that requires a login, consider placing the login request in this controller since each thread only needs to login once to establish a session.

暂完结。

猜你喜欢

转载自blog.csdn.net/gys666/article/details/80449593