使用Include Controller模块化接口用例

对于jmeter中重复使用的一些sampler,例如注册,可以使用Include Controller模块对用例做简化。如何操作呢?以注册为例,首先,先将注册部分的几个sampler放到一个Test Fragment下面,保存这个jmx文件,命名为login.jmx。然后在测试线程组中添加一个include controller,配置要引入的Test Plan为刚才保存的login.jmx。然后就可以使用了。


2628275-871f4fca4f20cd12.png
image.png

2628275-f61c23f25043a9d0.png
image.png

我最开始尝试用的时候,将注册的这个sampler加入到了一个线程组中,这时是不生效的,即在测试中引入外部jmx时是不会执行的,将sampler放到Test Fragment中就生效了。看了下官方的文档,文档描述的意思也是将sampler或者控制器等放入Test Fragment,而对于放到线程中的解释是可以在调试的时候使用。

摘抄一下官网的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.

include controller用来引入外部的JMX文件。使用它时,需要在一个测试计划中添加一个测试片段,并在测试片段中加入任何想要的samplers,controllers或者其他元件。然后保存这个测试计划。之后这个文件就可以被其他测试计划引用了。

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.

方便起见,一个线程组也可以被加入到外部的JMX文件中,这样方便调试。也可以使用一个模块控制器来引用这个测试片段。而在内部程序中这个线程组将会被忽略掉。

If the test uses a Cookie Manager or User Defined Variables, these should be placed in the top-level test plan, not the included file, otherwise they are not guaranteed to work.

如果测试中使用了一个cookie管理器或者用户组定义的变量,这些需要在最顶层的测试计划中定义,而不是在包含的这个文件中,不然的话,这个配置就不会生效。
这里的注册模块中就用到了一些用户自定义的变量,在调用者的这个测试计划中即文中的Medchart_SuiFang_TestCase中有定义。

Include Controller官方介绍:http://jmeter.apache.org/usermanual/component_reference.html#Module_Controller
其他参考:
https://blog.csdn.net/XiaoXiao_RenHe/article/details/83013170

猜你喜欢

转载自blog.csdn.net/weixin_34055910/article/details/87096417