Functional Web Services Testing Made Easy with SoapUI - Part 3
4. Code Coverage using Cobertura
There are many open source tools available to identify line and branch coverage. By using these, you can find areas in your test code that need more tests. In most cases, when a developer checks in something, the commit build runs, which in turn runs the unit tests and some integration tests. A secondary build, often run at night, can instrument your code for code coverage reporting, deploy to the application server, and run the available tests. This will create a detailed report that the team can see first thing in the morning.
Cobertura is a code coverage analysis tool for Java. You can use it to determine what percentage of your source code is exercised by your unit tests. Cobertura adds instrumentation directly to the bytecode and is easy to integrate with Apache Ant. It comes with its own Ant task definitions for you to use.
The steps to follow here are simple:
1. Change the build file to instrument the code. Here are the changes we need in the build file to instrument our source code:
<target name="instrument" depends="compile">
<cobertura-instrument datafile="${cobertura-data-dile}" todir="${classes.dir}">
<fileset dir="${classes.dir}">
<include name="**/*.class" />
</fileset>
</cobertura-instrument>
</target>
2. Deploy the instrumented code to GlassFish. Once the code is instrumented, deploy it your application server. The ant task provided here is for GlassFish V2 application server.
<target name="gf2-deploy-ear" depends="instrument">
<echo message="Deploying webservices-samples"/>
<taskdef name="sun-appserv-deploy" classname="org.apache.tools.ant.taskdefs.optional.sun.appserv.DeployTask"
classpath="${GLASSFISH_HOME}/lib/sun-appserv-ant.jar" />
<sun-appserv-deploy user="admin"
passwordfile="${passfile}"
host="localhost" port="8484"
file="${ear-file-name}" asinstalldir="${GLASSFISH_HOME}"/>
</target>
3. Generate a report. Cobertura stores coverage information to a file called cobertura.ser. Using the report task, Cobertura can generate coverage reports in either HTML or XML format.
<target name="coverage-report" depends="run-soapui-tests">
<cobertura-report datafile="${cobertura-data-dile}" srcdir="${src.dir}" destdir="${coverage.xml.dir}" format="xml"/>
<cobertura-report datafile="${cobertura-data-dile}" srcdir="${src.dir}" destdir="${coverage.html.dir}" />
</target>
5. Integrate these reports with Hudson using the Cobertura plug-in.
Installing a Hudson plug-in is as simple as installing Hudson. Download the latest version of the plug-in from here,
click the Manage Hudson link from Hudson's homepage. Next, click the Manage Plugins link, where you can upload the plug-in archive file. Once the plug-in has been installed, you'll have to restart Hudson. If everything goes well, you should be able to see a screen like:
- Login or register to post comments
- 19283 reads
- Printer-friendly version
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)










Comments
David Sills replied on Mon, 2008/05/19 - 8:46am
SumaBS replied on Mon, 2008/05/19 - 1:34pm
Sreekant replied on Thu, 2008/05/22 - 3:32pm
hi
I would like to know whether SOAPUI support complextype as input values.
2. whether it provides UI based support of testing Webservices
3. whether it generate test result in the report fasion.
if you have any product which support all these let me know.
Sreek
Meera Subbarao replied on Thu, 2008/05/22 - 4:10pm
Hi Sreekant,
Everything you have asked above is what SoapUI is. Also, the AccountManagerBean code shown in this page has all the methods except remove method return a complex type, which in my case is the Account entity object. And the create method does take Account as its input as shown below.
srimaan replied on Sun, 2008/07/20 - 2:12pm
arazauci@gmail.com replied on Fri, 2008/08/01 - 8:49pm
hi,
I am trying to specify my Test Report XML from soapui
as
C:\Results\2008-08-01_17-32-28\28\report.xml
and I get teh following error in hudson.
What am I doing wrong. why am I getting this error when the report.xml file exists.
tommy.van.mella... replied on Thu, 2008/09/04 - 6:37am
in response to: arazauci@gmail.com
If it is the same cause as in the Test case setup script, then it is the slash.
You used a "backward" slash. It should be a "forward" slash "/" .
Tommy
arazauci@gmail.com replied on Thu, 2009/04/23 - 1:22pm
samanthayan replied on Tue, 2009/06/16 - 9:23pm
sunrise1 replied on Fri, 2009/10/23 - 5:53am
sunrise1 replied on Fri, 2009/10/23 - 5:53am
sunrise1 replied on Sun, 2009/10/25 - 8:48am