{"id":31,"date":"2018-03-25T11:10:31","date_gmt":"2018-03-25T11:10:31","guid":{"rendered":"http:\/\/berkkibarer.com\/?p=31"},"modified":"2018-03-26T19:43:59","modified_gmt":"2018-03-26T19:43:59","slug":"designing-test-plans-with-controllers-the-right-way","status":"publish","type":"post","link":"https:\/\/www.berkkibarer.com\/?p=31","title":{"rendered":"Designing Test Plans with Controllers the Right Way"},"content":{"rendered":"<h3>As seen on: Loadium.com;<\/h3>\n<p><a href=\"https:\/\/loadium.com\/designing-test-plans-with-controllers-the-right-way\/\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-32\" src=\"http:\/\/berkkibarer.com\/wp-content\/uploads\/2018\/03\/loadium-1@2x-e1521976024407.png\" alt=\"\" width=\"112\" height=\"32\" srcset=\"https:\/\/www.berkkibarer.com\/wp-content\/uploads\/2018\/03\/loadium-1@2x-e1521976024407.png 306w, https:\/\/www.berkkibarer.com\/wp-content\/uploads\/2018\/03\/loadium-1@2x-e1521976024407-300x86.png 300w\" sizes=\"auto, (max-width: 112px) 100vw, 112px\" \/><\/a><\/p>\n<hr \/>\n<p class=\"p1\"><span class=\"s1\">JMeter Load &amp; Stress testing might seem very straightforward with a little practice, but in big scale projects, things can get complicated. Test plans can be broken, it might be hard to keep the design clean, and it could become a burden for the team to maintain the flow in the long run.<\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">Like most things in life, the very same rule applies for JMeter: \u201cSimple can be harder than complex\u201d\u00a0<i>Steve Jobs<\/i>.<\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">To create a well-organized and smoothly maintainable test in the long run, in this article we will focus on JMeter Controllers and how they can ease our pain.<\/span><\/p>\n<p class=\"p2\"><span class=\"s1\"><b>Storyline:<\/b><\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">In the name of modularity, JMeter provides us Module Controller combined with either Simple Controller or Test Fragment. It is convenient, yet efficient to empower such controllers with Parameterized Controller, Include Controller, Loop Controller, Random Controller, Interleave Controller, Recording Controller, Throughput Controller, Once Only Controller and RunTime Controller.<\/span><\/p>\n<p class=\"p2\"><span class=\"s1\"><b>Tagline:<\/b><\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">Once you start digging deeper, reorganizing and refactoring for every step plays a vital role to keep your design simple, neat and progressive.<\/span><\/p>\n<p class=\"p2\"><span class=\"s1\"><b>Keeping things modular<\/b><\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">Cached pages \u2013pages that are not supposed to be regenerated on the fly-, not-supposed-to-be-cached pages \u2013pages that are meant to be served with real-time data, linked user scenarios, data-driven load tests and such plans need to be run on a well-established design. If the case is based on reliable and sustainable plans \u2013hopefully, what we all expect-, there is a big chance to get lost in components farm and bring the current situation to an even more complex one than before.<\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">At this very point, Module Controller comes in handy. We can simply create test step blocks with either Simple Controller or Test Fragment. These side elements are at our service to help us improve code re-usability. By adding a module controller under our test plan, we will be able to use these thread groups for each plan we prepare. We can also save a Test Fragment as a JMX file and pass it into the plans by simply adding an Include Controller to our test plan. These approaches not only improve the re-usability and centralized management but also support the external folder structure, versioning, and relocation.<\/span><\/p>\n<p class=\"p2\"><span class=\"s1\"><b>Let\u2019s spice it up a little<\/b><\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">So everything is great so far. We got familiar with Jmeter and following the tips above, now that we know how to handle the modularity. Let\u2019s go one step further and place some extra elements into our test plans to be sure that things are set the way we want exactly.<\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">There could be a few questions you need to deal with while preparing your plans;<\/span><\/p>\n<p class=\"p3\"><span class=\"s1\"> \u2022 How many times do you want your tests to repeat? And how can you set the cycles for each module in its scope specifically?<\/span><\/p>\n<p class=\"p3\"><span class=\"s1\"> \u2022 Do you want your tests to run randomly or in sequential order?<\/span><\/p>\n<p class=\"p3\"><span class=\"s1\"> \u2022 Is there supposed to be a time-out separately for each test group?<\/span><\/p>\n<p class=\"p3\"><span class=\"s1\"> \u2022 Do you need to distribute the load by thread count or percentage over the test groups?<\/span><\/p>\n<p class=\"p3\"><span class=\"s1\"> \u2022 Do you need to run a request only once per thread?<\/span><\/p>\n<p class=\"p2\"><span class=\"s1\"><b>How many times do you want your tests to repeat? And how can you set the cycles for each module in its scope specifically?<\/b><\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">In your thread group settings, it is possible to set the loop count for the entire steps block. But what happens if we need to repeat the requests for a set of requests inside this cycle?<\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">Loop Controller comes to the rescue at this very moment. You can easily add Loop Controller under your thread group and place desired request steps under it.<\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">Loop Controller presents us two options to overcome in-scope-looping situation: Forever and loop count. When you check the forever option, requests in this scope simply are repeated forever. If you choose to set loop count, \u00a0the requests will run as many as the assigned number.<\/span><\/p>\n<p class=\"p2\"><span class=\"s1\"><b>Do you want your tests to run randomly or in a sequential order?<\/b><\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">All three controller elements \u2013 Random Controller, Random Order Controller and Interleave Controller- have their own way to change the request flow. The main difference between them is executing the requests once per cycle or all per cycle.<\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">Once per cycle: Once you execute a group of requests under the related controller, it picks one of the requests and runs it only.<\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">All per cycle: Once you execute a group of requests under the related controller, it runs it all.<\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">Random Order Controller is an all-per-cycle kind of element. On the other hand, Random Controller and Interleave Controller is a once-per-cycle type of element.<\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">To visualize, a concise example would be;<\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">We have a thread group with loop setting set to 2. Under this thread group, we have all three controllers mentioned above. Now we add two requests for each controller element. Basically what we have is as the following;<\/span><\/p>\n<p class=\"p3\"><span class=\"s1\"> \u2022 Test Plan<\/span><\/p>\n<p class=\"p3\"><span class=\"s1\"> \u2022 Thread Group<\/span><\/p>\n<p class=\"p4\"><span class=\"s2\">\u25e6<\/span><span class=\"s1\"> Random Order Controller<\/span><\/p>\n<p class=\"p5\"><span class=\"s2\">\u25aa<\/span><span class=\"s1\"> Request #1<\/span><\/p>\n<p class=\"p5\"><span class=\"s2\">\u25aa<\/span><span class=\"s1\"> Request #2<\/span><\/p>\n<p class=\"p4\"><span class=\"s2\">\u25e6<\/span><span class=\"s1\"> Random Controller<\/span><\/p>\n<p class=\"p5\"><span class=\"s2\">\u25aa<\/span><span class=\"s1\"> Request #1<\/span><\/p>\n<p class=\"p5\"><span class=\"s2\">\u25aa<\/span><span class=\"s1\"> Request #2<\/span><\/p>\n<p class=\"p4\"><span class=\"s2\">\u25e6<\/span><span class=\"s1\"> Interleave Controller<\/span><\/p>\n<p class=\"p5\"><span class=\"s2\">\u25aa<\/span><span class=\"s1\"> Request #1<\/span><\/p>\n<p class=\"p5\"><span class=\"s2\">\u25aa<\/span><span class=\"s1\"> Request #2<\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">Once we run the group with the Random Order Controller, we get the following result in our reports;<\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">Request #2<\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">Request #1<\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">Request #1<\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">Request #2<\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">As you notice already, 2 loop x 2 files mean 4 requests in a random manner.<\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">Similarly, as we run the ones with Random Controller, we get;<\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">Request #2<\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">Request #1<\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">2 loop x 2 files but for this controller type, it means 1 request picked for each cycle in a random manner.<\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">Last but not least, when we run the requests under Interleave Controller, we get;<\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">Request #1<\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">Request #2<\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">Two loop x 2 files again but also for this controller type, again it means one request picked for each cycle sequentially<\/span><\/p>\n<p class=\"p2\"><span class=\"s1\"><b>Is there supposed to be a time-out separate for each test group?<\/b><\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">There might be some situations to run the requests for a specific period. Runtime Controller is the one you are looking for.You set the runtime in seconds, and your group will run and stop exactly right after the number of seconds you entered.<\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">Just one thing that might lead to confusion though\u2026 This controller overrides the loop and continues for the given period. Therefore, if you set 30 seconds for Runtime Controller and set the Thread Group loop set to 1 but your request set is supposed to be done in 5 seconds then it will run six more times.<\/span><\/p>\n<p class=\"p2\"><span class=\"s1\"><b>Do you need to distribute the load by thread count or percentage over the test groups?<\/b><\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">There might be situations that require testing endpoints with relatively more load than any other. In this case, Throughput Controller provides us two options: thread count or percentage.<\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">By using Throughput Controller, \u00a0just like other controller elements mentioned above, with either of these options makes us easily share the load between the requests in no time.<\/span><\/p>\n<p class=\"p2\"><span class=\"s1\"><b>Do you need to run a request only once per thread?<\/b><\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">If you face this kind of situation, just add Once Only Controller, and you are good to go. It does the job and executes the request only once and in the first loop only for each thread.<\/span><\/p>\n<p class=\"p2\"><span class=\"s1\"><b>Sticky Notes<\/b><\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">Please keep in mind that all those modularity elements can easily be combined with JMeter\u2019s built-in CSV support or custom BeanShell scripts to pass any desired data into the plans.<\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">By using a Recording Controller beyond all the concepts discussed in this article, you can have your request steps created automatically for you. Even though this type of controller does not affect your design, it is a very handy choice to ease your manual work.<\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">If you\u2019re interested in using\u00a0<a href=\"https:\/\/loadium.com\/using-css-selectors-in-jmeter-scripts\/\"><span class=\"s3\">CSS selectors in JMeter Scripts<\/span><\/a>, then go and enjoy our blog!<\/span><\/p>\n<p class=\"p1\"><span class=\"s1\">Happy Load Testing\u2026<\/span><\/p>\n<hr \/>\n<p>References :\u00a0<a href=\"https:\/\/loadium.com\/designing-test-plans-with-controllers-the-right-way\/\">https:\/\/loadium.com\/designing-test-plans-with-controllers-the-right-way\/<\/a><\/p>\n<p>Berk Kibarer<\/p>\n ","protected":false},"excerpt":{"rendered":"<p>As seen on: Loadium.com; JMeter Load &amp; Stress testing might seem very straightforward with a little practice, but in big scale projects, things can get complicated. Test plans can be broken, it might be hard to keep the design clean, and it could become a burden for the team to maintain the flow in the long run. Like most things in life, the very same rule applies for JMeter: &ldquo;Simple can be harder than complex&rdquo;&nbsp;Steve Jobs. To create a well-organized and smoothly maintainable test in the long run, in this&hellip;<\/p>\n","protected":false},"author":1,"featured_media":34,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_wp_rev_ctl_limit":""},"categories":[1],"tags":[15,4,16,8,18,17,5],"class_list":["post-31","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-published","tag-controllers","tag-jmeter","tag-load-test","tag-loadium","tag-performance-test","tag-stress-test","tag-test"],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/www.berkkibarer.com\/index.php?rest_route=\/wp\/v2\/posts\/31","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.berkkibarer.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.berkkibarer.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.berkkibarer.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.berkkibarer.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=31"}],"version-history":[{"count":18,"href":"https:\/\/www.berkkibarer.com\/index.php?rest_route=\/wp\/v2\/posts\/31\/revisions"}],"predecessor-version":[{"id":183,"href":"https:\/\/www.berkkibarer.com\/index.php?rest_route=\/wp\/v2\/posts\/31\/revisions\/183"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.berkkibarer.com\/index.php?rest_route=\/wp\/v2\/media\/34"}],"wp:attachment":[{"href":"https:\/\/www.berkkibarer.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=31"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.berkkibarer.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=31"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.berkkibarer.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=31"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}