Pages

Wednesday, July 21, 2010

SoapUI, Junit and Ant

In my current project , we are focusing more on automated unit testing. This will keep us away from any surprises on production deployment. But more importantly this is the best way to verify multiple environments behaving correctly.Configure your test scripts to run against that environment and check the result.
From a developers point of view, this is the best way to prove I didn't break any of the existing code !.
Things are grown beyond Junit testing.In the web services world ,writing Junit test cases is not that fancy. Since tools like SoapUI is available for free, why to waste our time . More over handling soap messages in Junit testcases is troublesome. Now the question is how can run the SoapUI testcases along with other Junit testcases.
We have to run all our test cases from a  ant target. Here is the  ant target sample which does that.
_______________________________________________________________   
  
        <target name="soapui">
        <delete dir="${results}" />
        <mkdir dir="${results}" />
        <exec dir="${soapui}" executable="cmd.exe">
            <arg value="/c" />
            <arg value="testrunner.bat" />
            <arg value="-h" />
            <arg value="${server.port}" />
            <arg value="-j" />
            <arg value="-r" />
            <arg value="-f" />
            <arg value="${results}" />
            <arg value="${path}/${soapui.file.name}" />
        </exec>
        <resourcecount property="count.failed">
            <fileset dir="${results}">
                <include name="*-FAILED.txt" />
            </fileset>
        </resourcecount>
        <condition property="isFailed">
            <not>
                <equals arg1="${count.failed}" arg2="0" />
            </not>
        </condition>
        <echo message="${count.failed} SOAP UI testcase(s) failed" />
      
        <fail message="Test Failed :-(" if="isFailed" />
        <echo message="Test Succeeded :-)" />
    </target>
           
           _______________________________________________________________
SoapUI generates  *-FAILED.txt  for each of failed test cases. by counting those  we can even determine how many test cases failed. By using  "-j" option we can generate Junit friendly report page.

Actually , testrunner.bat has a bunch of useful command line arguments . Find out more :
http://www.soapui.org/Test-Automation/functional-tests.html
Related Posts Plugin for WordPress, Blogger...