DEV-NOTES|SoapUI: Run random tests in a load test

Sometimes it is useful to set up a SoapUI test for simulating different usage scenarios randomly. The following solution provides a random selection from prepared test steps resulting in a different behavior of the tested service.

Setting up the test environments includes three steps:

  1. Create test suite containing test cases for each desired scenario
    20140727_DynamicTestingSoapUI_Navigator
  2. Create test suite with one test case which contains at least one groovy test step for the dynamic test step selection containing the following code:

    <br />
    import org.apache.log4j.Level<br />
    import java.util.Random</p>
    <p>// just for debuging - change to Level.SEVERE for actually running the test<br />
    log.setLevel(Level.DEBUG)<br />
    log.debug(&quot;selecting a test case&quot;)</p>
    <p>// get project for test case for later test step selection<br />
    def project = testRunner.getTestCase().getTestSuite().getProject()<br />
    log.debug(&quot;Project: &quot;+project)</p>
    <p>// select test suite which provides the prepared test step<br />
    def suite = project.getTestSuiteByName(&quot;CalculatorService TestSuite&quot;)</p>
    <p>// -- only for debugging: print test cases<br />
    def allTestCases = suite.getTestCaseList()<br />
    for(def tc : allTestCases) {<br />
      log.debug(&quot;\t Test Case: &quot;+ tc.getName())<br />
    }</p>
    <p>// select test case from which the test steps are taken<br />
    def selectedTestCases = allTestCases</p>
    <p>// randomly select test step by index from the given test suite<br />
    // you might adjust the behavior by modifying the probability of<br />
    // the resulting index<br />
    def idx = Math.abs( (new Random()).nextInt() % selectedTestCases.size())<br />
    log.debug(&quot;selected index: &quot;+idx)</p>
    <p>// select test based on randomly calculated index<br />
    def selectedTest = selectedTestCases.get(idx)<br />
    log.debug(&quot;Running test: &quot;+ selectedTest.getName())</p>
    <p>// execute test<br />
    def result = selectedTest.run(context.getProperties(), false)<br />
    //log.debug(&quot;Test result is: &quot;+ result.getStatus())</p>
    <p>// propagate result back to the originating test step<br />
    return result</p>
    <p>

  3. Set up load test using the „dynamic“ test case for simulating different users behavior.
    20140727_DynamicTestingSoapUI_LoadTest

The basic idea is selecting the test step based on the randomly calculated index from a list of test cases provided by a dedicated test suite. The given example facilitates a simple model for index selection, but it is expandable to model more sophisticate algorithms for index calculation. One example for a slightly improved might by the calculation of a weighted index. This might be useful if the expected characteristics are known, like testing an query service supposed to have about 60% of all requests being no hits.

Running the load test based on the dynamic selection offers a facile opportunity of modeling  a more user like behavior testing the service implementation tailored to the expected characteristics for given scenarios.

Ein Gedanke zu „DEV-NOTES|SoapUI: Run random tests in a load test“

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

4 × eins =