One of the 7 deadly sins of the coding universe is the unnecessary duplication of code.
How can we avoid the 'deadly dupe' in JMeter?
Sometimes one comes across a complex piece of a test plan with large amounts of used variables and functions. But, if you need to use the same segment more than once, or even twice, what can you do?
One option is to create a Bean Shell script in a separate file and to call it BeanShellSampler. But, it can be difficult to track the execution of various parts of such a complex scenario.
Is there any other way to do it? You betcha.
It is the logic controller – Module Controller.
The JMeter Module Controller allows switching between pieces of the test plan. Each piece is a controller that contains child elements. These controllers can either be placed in Thread Group or in Workbench.
The test plan contains several Simple Controllers with child HTTP Requests inside. Simple Controller does not verify any conditions, it just combines several samples into one element. So, if the Module Controller were disabled before executing the test plan, we receive the following picture in View Results Tree.
Samples from Simple Controllers 1&2 were executed. Now, enable Module Controller and select Simple Controller 1 therein.
Now start the test plan again. Results below.
As specified in the JMeter Manual, Module Controller can execute samples either from Thread Group or from Workbench.
Let’s verify scenario 2.
Configure Module Controller to use Simple Controller 3 that is placed in Workbench.