RE: Possible to use with Cobertura?
"Bret Kumler" <[email protected]>
| Newsgroups | gmane.comp.jakarta.cactus.user |
|---|---|
| Message-ID | <24F7E976D2C85149A4785E11309B603303F0A5CA@traveler> |
You need to add the instrumented classes to the war file.
I create a war file with the instrumented classes in it, then cactify
the war file. This is the sample below.
<war destfile="${test-war.dir}/test.war"
webxml="${web-build-meta.dir}/web.xml">
<classes dir="${instrumented.classes}"/>
<lib dir="${web-build-libs.dir}" />
<zipfileset dir="${web-build.dir}">
<exclude name="pages/**"/>
<exclude name="WEB-INF/**"/>
</zipfileset>
<zipfileset dir="${web-build.dir}/pages" prefix="pages"/>
<zipfileset dir="${web-build-meta.dir}" prefix="WEB-INF">
<exclude name="classes/**"/>
<exclude name="lib/**"/>
</zipfileset>
<zipfileset dir="${web-build-classes.dir}">
<exclude name="com/**"/>
</zipfileset>
</war>
<cactifywar srcfile="${test-war.dir}/test.war"
destfile="${test-war.dir}/${app.name}-${app.version}.war"
mergewebxml="${meta.dir}/${configtype}/test/cactus-web.xml">
<lib file="${thirdparty.dir}/${strutstest.lib}"/>
<fileset dir="${meta.dir}/${configtype}/test"
excludes="cactus-web.xml" />
</cactifywar>
The other thing is you are calling the reporting task before the test is
run. <target name="test" depends="unittest, code-coverage-report"/>
You need to move the code-coverage-report depend out of this target.
It should be
<target name="code-coverage-report" depends="test"/>
<target name="test" depends="unittest"/>
And u should call "code-coverage-report" target 1st.
-----Original Message-----
From: news [mailto:[email protected]] On Behalf Of Ryan
Sent: Wednesday, May 03, 2006 9:35 AM
To: [email protected]
Subject: Re: Possible to use with Cobertura?
Here are snippits of my build.xml. I have gone over and over it and
still
cannot find the reason why Cobertura reports 0% coverage for my servlet
tests.
The tests run ok and the "unit-test-results" are created, but it seems
that the
test are not being saved to the cobertura.ser file. That is my guess at
least.
What am I doing wrong? Very frustrated, and again, thanks fort he
help.
...
<!-- Setup cobertura instrumented test classes -->
<target name="code-coverage-setup" depends="compile">
<delete file="${coberturaDataFile}"/>
<delete dir="${instDir}"/>
<mkdir dir="${testingDir}"/>
<!-- build instrumented class files for code coverage testing -->
<cobertura-instrument todir="${instDir}"
datafile="${coberturaDataFile}">
<ignore regex="org.apache.log4j.*" />
<fileset dir="${buildDir}">
<include name="**/*.class"/>
<exclude name="**/*Test.class"/>
<exclude name="**/test/*"/>
</fileset>
</cobertura-instrument>
</target>
...
<target name="code-coverage-report">
<!--Generate a series of HTML files containing the coverage
data in a user-readable form using nested source filesets.-->
<cobertura-report datafile="${coberturaDataFile}"
destdir="${codeCoverageReportDir}">
<fileset dir="${srcJavaDir}">
<include name="**/*.java"/>
<exclude name="**/*Test.java"/>
<exclude name="**/test/*"/>
</fileset>
</cobertura-report>
</target>
...
<!-- Run to setup instrumented class files, run unit tests and generate
coverage
reports-->
<target name="test" depends="unittest, code-coverage-report"/>
<!-- unit testing -->
<target name="unittest" depends="code-coverage-setup">
<!-- clean the test-results folder -->
<delete dir="${unitTestResultsDir}"/>
<!-- create the test-results folder -->
<mkdir dir="${unitTestResultsDir}/cactus"/>
<!-- invoke cactus -->
<cactus warfile="${distDir}/${warName}-cactified.war"
fork="yes"
haltonfailure="no"
failureproperty="tests.failed">
<!--
Specify the name of the coverage data file to use.
The value specified below is the default.
-->
<sysproperty key="net.sourceforge.cobertura.datafile"
file="${coberturaDataFile}"/>
<!--
Note the classpath order: instrumented classes are before the
original (uninstrumented) classes. This is important.
-->
<classpath>
<pathelement path="${instDir}"/>
<pathelement path="${buildDir}"/>
<pathelement path="${buildDir}/Cactus"/>
<pathelement path="${cobertura.dir}/cobertura.jar"/>
</classpath>
<!--
The instrumented classes reference classes used by the
Cobertura runtime, so Cobertura and its dependencies
must be on your classpath.
-->
<classpath refid="cobertura.classpath"/>
<containerclasspath>
<pathelement location="${cobertura.dir}/cobertura.jar"/>
</containerclasspath>
<!-- set log4j.configuration system property -->
<jvmarg
value="-Dlog4j.configuration=file:${testLoggingProperties}"/>
<!-- define the classpath
<classpath refid="project.class.path"/>-->
<classpath>
<path refid="project.class.path"/>
<pathelement location="${cobertura.dir}/cobertura.jar"/>
<pathelement location="${cactus.dir}/lib/httpunit-1.6.jar"/>
<pathelement location="${cactus.dir}/lib/nekohtml-0.9.1.jar"/>
<pathelement location="${thirdPartyLibsDir}"/>
</classpath>
<!-- define the formatter -->
<formatter type="brief" usefile="false"/>
<formatter type="plain"/>
<containerset>
<tomcat5x if="cactus.home.tomcat5x"
dir="${cactus.home.tomcat5x}"
port="${cactus.port}"
output="${testingDir}/cactus.out"
todir="${unitTestResultsDir}/cactus"
serverxml="${cactus.home.tomcat5x}/conf/server.xml"/>
</containerset>
<!-- setup for batch-testing -->
<batchtest fork="yes" todir="${unitTestResultsDir}">
<fileset dir="${buildDir}/Cactus">
<include name="**/*ServletTest.class"/>
</fileset>
</batchtest>
</cactus>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
This e-mail message and any attachments may contain private, confidential, proprietary or privileged material of GoldenGate Software, Inc. that is for the sole use of the intended recipient(s) of this e-mail message. Any review, copying or distribution or other use of this e-mail message or any attachments hereto by anyone other than the intended recipient(s) is strictly prohibited. If you are not the intended recipient(s) of this e-mail message, please contact GoldenGate Software, Inc. (415-777-0200) immediately and permanently delete the original e-mail message and any copies of this e-mail message and all attachments, if any.