soapUI inline request parameterization made simple using static Java methods

Maintainability and reuse when using a lot of Groovy scripting or in-house Java libs with the free version of soapUI can be really cumbersome. The same groovy code snippets are all over the place, it does not matter if a lot of core functionality is mapped into the java libraries there are still some Groovy code to be written to get this to work in the long run.

I recently had to struggle creating maintainable test suites covering more than 200 test cases and in total easily more than a thousand different requests. There was a clear need for making the test suites easy to maintain and extend. Removing all the duplicated Groovy code was the top priority. Blow is the usual scenario we had for the majority of our tests in the beginning.

A) Groovy script

  • importing any bin/ext java libraries
  • invoking a given method the e.g. creates a timestamp value
  • put the generated timestamp into a test case property

B) Test request

  • inline expansion of the test case property

This was really an overkill approach when dealing with hundreds and hundreds of different test requests. So how to get this in to small one-liners inside the requests directly without even having to deal with test case properties asf..

Using static Java methods

Just implement a set of static Java methods and inline these in your test requests. No need for library imports or instance creation just call the method needed with arguments that in turn can be dynamically created.

Below is an example class that can be added to a jar file put in the soapUIinstallation/bin/ext folder.

public class TimeStampCreator {
  public static String getToday() { ... }
  public static String getTodayPlusDays(int days) { ... }
  public static String getTodayMinusDays(int days) { ... }

The methods above can be called accordingly as described in the TestRequest (SOAP) example below, note the nested test case parameter expansion.

<args xsi:type="api:ArrayOf_xsd_string" soapenc:arrayType="xsd:string[]">

Works like a charm…


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: