Performance tests involve simulating user behavior of critical business scenarios. Often there are sizable parts of these user actions that often involve repeated actions in different business scenarios. Often we come across complex pieces within a test plan involving large amounts of user variables and functions. While that is a cool, nice way of simulation, what if you need to use the same segment more than once? One option is to create a Beanshell script in a separate Beanshell Sampler file and to call that Beanshell Sampler at different places where it is needed. However, it can be difficult to track the execution of various parts of such repeated complex scenarios.
Do we have a smarter and efficient way to handle this? JMeter’s Module Controller is the key to improving efficiency in your scripting exercise. Module controller allows you to redirect test execution to a given fragment of the test or selected module. Modular Controller or Modularization process is effectively involved in isolating small units of functionality (i.e.log-in, log-out, search operations) which consist of repetitive requests that implement the functionality.
These small units of functionality can be stored in Simple Controllers as modules which can be linked together quickly to form tests. Module Controller facilitates this by acting as a pointer to any controller that sits under the JMeter Workbench. The controller and its sub elements will be substituted in place of the Module Controller at runtime.
The rationale for this approach is that these high-volume repetitive functional activities can be managed at a single module. Even if there are changes done to the implementation, it will need us to only make the update in a single location rather than across multiple locations of your test plan. If your business functionality is only used once in a single script rather than many scripts it makes no sense to modularize. However, if it is used more than once then we should consider Modular scripts.
The way that JMeter approaches the subject of modularization is in the form of Test Fragments combined with Module Controllers and these approaches are extremely useful when you have complicated tests that support many concurrent user journeys. This is extremely handy as we often run into scenarios of such complexity in our scripting exercise.
While leveraging Modular Controllers gives great efficiency in our scripting, we need to adhere to discipline in our scripting standards. If you are going to use a modularized approach then we need to ensure that each module can carry on where the previous one left off with no missing steps. For example, if we modularize our log-on and the log-on finishes with the application at a certain place and state then all scripts that execute directly after our log-on must start from the place the modularized log-on component left the application under test.
At the outset of our performance testing journey when you only have a handful of scenarios to script the tests, the effort to modularize them can seem like an overhead you don’t really want. However, when our tests start to grow and as the application we are testing evolves and changes we will see the benefits of Modularization.
Key point to remember is that modularization in JMeter helps in the distribution of the maintenance effort across a team, large complex scripts are difficult to debug and understand for someone who is unfamiliar with them. A small single function test is straightforward to understand and to maintain meaning the maintenance effort can be distributed in JMeter modularization approach.