Enterprise Integration Zone is brought to you in partnership with:

Software developer with 10+ years of experience of Java/Scala development. Currently working at Codeborne, a consulting software company based in Tallinn, Estonia, specializing in development of web-based self-service solutions like internet banks, booking systems, enterprise portals and other software. Andrei has posted 2 posts at DZone. You can read more from them at their website. View Full User Profile

SoapUI Tests with Ant+Ivy

04.24.2012
| 6100 views |
  • submit to reddit

Do you like quest games? Everybody does!

Today we had to play one. It's name was "run SoapUI tests with ANT script". It was the required step for accessing the next level: "Automated testing of our services on Continuous Integration server".

SoapUI is my de facto tool for testing SOA services. It has a Maven 2 plugin, and it's old enough to have Maven 1 plugin. But we are not quite lucky enough: SoapUI doesn't have Ant tasks.

This article shows how to run SoapUI tests from an Ant script. We suppose you are already using Apache Ivy in this tutorial.

So, let's begin.

Ant script

The Ant task is simple enough:
<target name="test">
    <mkdir dir="test-results"/>
    <java classname="com.eviware.soapui.tools.SoapUITestCaseRunner" errorproperty="tests-failed" fork="yes" dir="test-results">
      <arg line="-j -f${basedir}/test-results"/>
      <arg value="-t${basedir}/soapui-settings.xml"/>
      <arg value="${basedir}/MY-SMART-soapui-project.xml"/>
      <classpath>
        <fileset dir="lib" includes="*.jar"/>
      </classpath>
    </java>

    <junitreport todir="test-results">
      <fileset dir="test-results">
        <include name="TEST-*.xml"/>
      </fileset>
      <report format="frames" todir="reports/html"/>
    </junitreport>

    <fail if="tests-failed"/>
  </target>

Ivy configuration

Next, you need to add corresponding dependencies to ivy.xml:
<dependencies defaultconf="default->default">
    <dependency org="junit" name="junit" rev="4.10+" />
    <dependency org="eviware" name="maven-soapui-plugin" rev="4.0.1" />
    <dependency org="net.sf.jtidy" name="jtidy" rev="r938+"/>
    <exclude org="jtidy" module="jtidy"/>
  </dependencies>
And finally, you need to add eviware.com repository to your ivysettings.xml:
<ivysettings>
  <settings defaultResolver="default"/>

  <resolvers>
    <ibiblio name="public" m2compatible="true"/>
    <ibiblio name="eviware" m2compatible="true" root="http://www.eviware.com/repository/maven2/"/>
    <chain name="default" returnFirst="true">
      <resolver ref="eviware"/>
      <resolver ref="public"/>
    </chain>
  </resolvers>
</ivysettings>
Note that eviware should come first, because it overrides some artifacts from the central repository, e.g. javax.jms:jms.

SoapUI settings

Typically all tests have some configuration parameters. In the case of SoapUI, it's common to declare them in global properties. Fortunately, these can be stored in a VCS within soapui-settings.xml:
<con:soapui-settings xmlns:con="http://eviware.com/soapui/config">
  <con:setting id="GlobalPropertySettings@properties"><![CDATA[<xml-fragment xmlns:con="http://eviware.com/soapui/config">
  <property xmlns="http://eviware.com/soapui/config">
    <name>MY_serverUrl
    <value>http://my-dev-server.chucknorris.com:8080
  </property>
  <con:property>
    <con:name>MY_dbConnectionString
    <con:value>jdbc:oracle:thin:chuck/donteventry@dev.chucknorris.com:1521:dev
  </con:property>
</xml-fragment>]]></con:setting>
</con:soapui-settings>

Running

Execute
ant test
and be prepared to download ~60 MB of jars. I have no idea why SoapUI needs so much (for example, why does it needs javax.jms?), but that's Java, guys. After running Ant tests, you will find JUnit-style HTML reports in folder reports/HTML, and several log files in the test-results folder for deeper debugging.

Troubleshooting

Missing dependencies

Since eviware repo overrides some artifacts from the central repository, you can get in trouble if some artifacts are already cached in your local repository. For example, we have had this problem with javax.jms:jms artifact. The central repository contains only poms claiming that there is no such jar, but eviware repo contains this jar. If the former has occasionally gotten downloaded into your local cache, you will get the following error:
[ivy:retrieve] :::: WARNINGS
[ivy:retrieve]   [NOT FOUND  ] javax.jms#jms;1.1!jms.jar (0ms)
[ivy:retrieve]  ==== public: tried
[ivy:retrieve]    http://repo1.maven.org/maven2/javax/jms/jms/1.1/jms-1.1.jar
[ivy:retrieve]   ::::::::::::::::::::::::::::::::::::::::::::::
[ivy:retrieve]   ::              FAILED DOWNLOADS            ::
[ivy:retrieve]   :: ^ see resolution messages for details  ^ ::
[ivy:retrieve]   ::::::::::::::::::::::::::::::::::::::::::::::
[ivy:retrieve]   :: javax.jms#jms;1.1!jms.jar
[ivy:retrieve]   ::::::::::::::::::::::::::::::::::::::::::::::
[ivy:retrieve] 
[ivy:retrieve] :: USE VERBOSE OR DEBUG MESSAGE LEVEL FOR MORE DETAILS
But the workaround is simple:
rm -fr ~/.ivy2/cache/javax.jms/jms

Conclusion

Although I find that SOA concepts are the offspring of the devil, SoapUI is a great tool for testing this, and automated testing is a great practice. Putting them together is a good level for the'programmer's quest game'. A Maven repository is the inevitable beast of satan at the end of level. Be patient and kill this boss.

Published at DZone with permission of its author, Andrei Solntsev. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags: