使用Include Controller模塊化接口用例

對(duì)于jmeter中重復(fù)使用的一些sampler,例如注冊(cè),可以使用Include Controller模塊對(duì)用例做簡(jiǎn)化。如何操作呢?以注冊(cè)為例,首先,先將注冊(cè)部分的幾個(gè)sampler放到一個(gè)Test Fragment下面,保存這個(gè)jmx文件,命名為login.jmx。然后在測(cè)試線程組中添加一個(gè)include controller,配置要引入的Test Plan為剛才保存的login.jmx。然后就可以使用了。


image.png

image.png

我最開始嘗試用的時(shí)候,將注冊(cè)的這個(gè)sampler加入到了一個(gè)線程組中,這時(shí)是不生效的,即在測(cè)試中引入外部jmx時(shí)是不會(huì)執(zhí)行的,將sampler放到Test Fragment中就生效了??戳讼鹿俜降奈臋n,文檔描述的意思也是將sampler或者控制器等放入Test Fragment,而對(duì)于放到線程中的解釋是可以在調(diào)試的時(shí)候使用。

摘抄一下官網(wǎng)的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用來(lái)引入外部的JMX文件。使用它時(shí),需要在一個(gè)測(cè)試計(jì)劃中添加一個(gè)測(cè)試片段,并在測(cè)試片段中加入任何想要的samplers,controllers或者其他元件。然后保存這個(gè)測(cè)試計(jì)劃。之后這個(gè)文件就可以被其他測(cè)試計(jì)劃引用了。

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.

方便起見,一個(gè)線程組也可以被加入到外部的JMX文件中,這樣方便調(diào)試。也可以使用一個(gè)模塊控制器來(lái)引用這個(gè)測(cè)試片段。而在內(nèi)部程序中這個(gè)線程組將會(huì)被忽略掉。

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.

如果測(cè)試中使用了一個(gè)cookie管理器或者用戶組定義的變量,這些需要在最頂層的測(cè)試計(jì)劃中定義,而不是在包含的這個(gè)文件中,不然的話,這個(gè)配置就不會(huì)生效。
這里的注冊(cè)模塊中就用到了一些用戶自定義的變量,在調(diào)用者的這個(gè)測(cè)試計(jì)劃中即文中的Medchart_SuiFang_TestCase中有定義。

其他:
如果要將測(cè)試用例jmx文件放到j(luò)enkins上運(yùn)行或者在別的電腦上運(yùn)行,Include Controller中設(shè)置的路徑需要是通用的,將自己的includeModule文件夾放置到bin目錄下,Include Controller中設(shè)置的路徑成includeModule/login.jmx,是可行的。由此可以推出Include Controller默認(rèn)路徑前綴是bin目錄。

image.png

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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容