Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modularizing JMeter tests?

We are looking to migrate our testing framework over to JMeter. We have 50 + test cases, each of them with repeating actions like Logging in and logging out for example. How can I modularize my approach?

What I'm looking for specifically is a "Add test item from file" so that I could for example, add the login code.

We also have things like connectionID's that need to be passed on every request. Is there anyway jMeter can AUTOMATICALLY replace all occurrences of it with a Jmeter variable? Atm the proxy-recorder records the actual connection string, and we have to manually replace that with ${connectionID}. Is there a better way?

like image 517
Dominic Bou-Samra Avatar asked Mar 22 '11 23:03

Dominic Bou-Samra


3 Answers

This works fine for me.

Make a new thread group at the bottom of the test plan and put a simple controller in it. Inside the simple controller put the code you want to repeat. I use two simple controllers but one is actually a DB test case suite. While keeping whatever is inside the thread group enabled, make sure to put the thread group itself as disabled, or else it will execute again on its own.

Now, in any particular test case, add User Parameters and add a Module Controller. The Module Controller can point to the simple controller section(s) you made before. Have the simple controller with a ${variables} set, then override them here inside the particular test you are running by putting the variable in the User Parameters. Thus you get the different variables and tests with the same suite.

I put a Simple Controller inside the Simple Controller to add lengthy db tests. This ends up as

Thread Group > Simple Controller > Simple Controller > JDBC Request. All are renamed.

You can select different ones in the Module Controller inside the tests. I have about six right now but this gets repeated dozens of times.

This is all with a stock Jmeter 2.3 . If you are in an environment such that you can't install the plugins, this will work fine. I've never tried them

HTH

like image 103
sf2k Avatar answered Sep 21 '22 23:09

sf2k


As far as automatically replacing the connection IDs, there is not, to my knowledge, a way to do that via the GUI. However, the test scripts are simple XML files and so it would be very easy to write a sed or awk script to do that replacement for you.

As far as the "add test file from here" part, in 2.6 (not sure about other versions, not used them) there is a logic controller called "Include Controller" that can load test snippets.There is also the ability to save snippets of test code called "test fragments" to their own .jmx files.

If you start a new test plan, right click on test plan then add -> test fragment -> test fragment this will add the container, then you can add your other requests in and use this chunk inside the aforementioned Include element.

If you are able to use the latest version, or if the prior versions support this, this may be a simpler option than writing your own plugin.

like image 36
Lee Lowder Avatar answered Sep 19 '22 23:09

Lee Lowder


By using below Jmeter elements, we can modularize the test scripts.

  1. Test Fragment
  2. Module Controller
  3. Parameterized Controller
  4. Include Controller

Please check this for more details & examples.

http://www.testautomationguru.com/jmeter-modularizing-test-scripts/

like image 30
vins Avatar answered Sep 19 '22 23:09

vins