You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-user@jakarta.apache.org by Ryan <gi...@strose.edu> on 2006/05/08 18:01:56 UTC

Still having trouble with Cobertura reports

I have tried everything I can think of and even took Bret Kumler's advise in the
earler postings.  The Cactus tests still run fine, the JUnit report reports that
the tests were sucessful, however for some reason, Cobertura is not working. 
Here are parts of my build.xml.  If anyone can see what I am doing wron please
let me know... Not beign able to figure this out is driving me insane!

Ryan



<project name="${projectName}" default="dist" basedir=".">
  <!-- project properties are in build.properties -->
  <property file="build.properties"/>

  <!-- set calculated properties for this build -->
  <property name="srcJavaDir" value="${srcDir}/Java"/>
  <!--added for cactus purposes-->
  <property name="srcCactusDir" value="${srcDir}/Cactus"/>
  <property name="instDir" value="${genDir}/Instrumented"/>

  <!-- location of instrumented Jars for code coverage testing -->
  <property name="testingDir" value="${genDir}/test"/>
  <property name="testingJAR" value="${genDir}/bin/test-${jarName}.jar"/>
  <property name="unitTestResultsDir" value="${genDir}/test/unit-test-results"/>
  <property name="coberturaDataFile" value="${testingDir}/cobertura.ser"/>
  <property name="codeCoverageReportDir"
            value="${testingDir}/code-coverage-report"/>
  
  <!-- Build the Classpath -->
  <path id="project.class.path">
  	<fileset dir="${thirdPartyLibsDir}">
      <include name="**/*.jar"/>
    </fileset>
    <fileset dir="${envLibsDir}">
      <include name="**/*.jar"/>
    </fileset>
  </path>
  
  <!--Build the cactus classpath-->
  <path id="cactus.classpath">
	<path refid="project.class.path"/>
	
	<fileset dir="${cactus.dir}">
      <include name="lib/*.jar"/>
    </fileset>
  </path>

  
  
  <!-- Code Coverage lib -->
    <property name="cobertura.lib"
              value="${cobertura.dir}/cobertura.jar" />
    
    <property name="asm.lib"
              value="${cobertura.dir}/lib/asm/asm-2.1.jar"/>
    
    <property name="cov-log4j.lib"
	      value="${cobertura.dir}/lib/log4j/1.2.9/log4j-1.2.9.jar" />
    
    <property name="ccl.lib"
              value="${cobertura.dir}/lib/ncss/21.41/ccl.jar"/>
    
    <property name="javancss.lib"
	      value="${cobertura.dir}/lib/ncss/21.41/javancss.jar" />
    
    <property name="jakarta-oro.lib"
	      value="${cobertura.dir}/lib/oro/jakarta-oro-2.0.8.jar" />


<!-- Setup for Cobertura - code coverage evaluation tool -->
  <path id="cobertura.classpath">
    <fileset dir="${cobertura.dir}">
      <include name="cobertura.jar"/>
      <include name="lib/**/*.jar"/>
    </fileset>
  </path>
  <taskdef classpathref="cobertura.classpath" resource="tasks.properties"/>
  
  

  <!-- setup steps required before compilation -->
  <target name="init">
	<taskdef resource="cactus.tasks" classpathref="cactus.classpath"/>
	
	<!-- Create the time stamp -->
    <tstamp/>
    <!-- Create the build directory structure used by compile -->
    <mkdir dir="${buildDir}"/>
    <mkdir dir="${buildDir}/Cactus"/>
    <mkdir dir="${distDir}"/>
    <mkdir dir="${genDir}/bin"/>
    
  </target>

  <!-- compilation -->
  <target name="compile.java" depends="init">
  <!-- Compile the java code from ${srcJavaDir} into ${buildDir} -->
    <javac srcdir="${srcJavaDir}" destdir="${buildDir}" debug="Yes"
source="${sourceVersion}">
      <classpath refid="project.class.path"/>
    </javac>
  </target>
  
  <target name="compile.cactus" depends="init">
    <!-- Compile the cactus java code from ${srcCactusDir} into ${buildDir} -->
    <javac srcdir="${srcCactusDir}" destdir="${buildDir}/Cactus" debug="Yes"
source="${sourceVersion}">
      <classpath>
        <path refid="cactus.classpath"/>
        <!-- <pathelement location="${httpunit.jar}"/> -->
        <!-- <pathelement location="${nekohtml.jar}"/> -->
        <pathelement location="${buildDir}"/>
      </classpath>
    </javac>
  
  </target>
  
  
  <target name="compile" depends="compile.java, compile.cactus"/>

  <!-- 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 datafile="${coberturaDataFile}" todir="${instDir}">
      <ignore regex="org.apache.log4j.*" />
      <fileset dir="${buildDir}">
        <include name="**/*.class"/>
        <exclude name="**/*Test.class"/>
        <exclude name="**/test/*"/>
      </fileset>
    </cobertura-instrument>  
  </target>
  
  <!-- Package up the test classes and added the test package to the war file -->

<target name="prepare.cactus" depends="code-coverage-setup">
<!--<mkdir dir="${test-lib.dir}"/>
	<mkdir dir="${test-war.dir}"/>
	<mkdir dir="${test-props.dir}"/>-->

        <!-- Temporary hack until cobertura bug is fixed -->
        <copy todir="${cactus.home.tomcat5x}/common/lib"
			  file="${cobertura.lib}"/>
			  
        <copy todir="${cactus.home.tomcat5x}/common/lib"
			  file="${asm.lib}"/>
			  
        <copy todir="${cactus.home.tomcat5x}/common/lib"
			  file="${cov-log4j.lib}"/>
			  
        <copy todir="${cactus.home.tomcat5x}/common/lib"
			  file="${ccl.lib}"/>
			  
        <copy todir="${cactus.home.tomcat5x}/common/lib"
			  file="${javancss.lib}"/>
			  
        <copy todir="${cactus.home.tomcat5x}/common/lib"
			  file="${jakarta-oro.lib}"/>
    
   

    <!--<mkdir dir="${dist.dir}/war" />-->

	<war warfile="${distDir}/${warName}.war" webxml="${srcDir}/web.xml"
             manifest="${srcDir}/${manifestForWAR}">
		<classes dir="${instDir}">
			<include name="**/*.class" />
		</classes>
		<lib dir="${thirdPartyLibsDir}"/>
		<classes dir="${buildDir}">
			<include name="**/*.class" />
			<exclude name="**/*Test.class" />
			<exclude name="**/test/*"/>
                </classes>
                <classes dir="${addlClassesDir}"/>
    </war>
    
    
    

         <!--Cactify the WAR-->
	<cactifywar srcfile="${distDir}/${warName}.war" 
				destfile="${distDir}/${warName}-cactified.war"
				mergewebxml="${srcDir}/cactus-web.xml">
		<classes dir="${buildDir}/Cactus"/>
    
		<lib file="${cactus.dir}/lib/httpunit-1.6.jar"/>
		<lib file="${cobertura.dir}/cobertura.jar"/>
		<lib dir="${thirdPartyLibsDir}"/>
    
    
    <servletredirector/>
    <servletredirector name="ServletRedirectorSecure"
					   mapping="/ServletRedirectorSecure"
					   roles="test"/>
	</cactifywar>

  </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, prepare.cactus">
    <!-- clean the test-results folder -->
    <delete dir="${unitTestResultsDir}"/>
    <!-- create the test-results folder -->
    
    <mkdir dir="${unitTestResultsDir}/cactus"/>
    <delete file="BSSTrainingWebLog.txt"/>

    <!-- invoke cactus -->
    <cactus fork="yes"
	    warfile="${distDir}/${warName}-cactified.war"              
            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}"/>
      
      <containerclasspath>
		<pathelement path="${testingJar}"/>
		<pathelement path="cobertura.classpath"/>
		<pathelement path="${srcCactusDir}"/>
      </containerclasspath>
            
      <!--
        Note the classpath order: instrumented classes are before the
        original (uninstrumented) classes.  This is important.
      
      <classpath location="${instDir}"/>
      <classpath location="${buildDir}"/>-->
      <classpath>
	<pathelement location="${instDir}"/>
        <pathelement location="${buildDir}"/>
        <pathelement location="${buildDir}/Cactus"/>
        <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}"/>
        <path refid="project.class.path"/>
    </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"/>
      
      
     
      
      <!-- set log4j.configuration system property -->
      <jvmarg value="-Dlog4j.configuration=file:${testLoggingProperties}"/>
      
      <!-- define the classpath -->
      <classpath refid="project.class.path"/>
     
    <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"/>
       <!-- jvmArgs="-Dnet.sourceforge.cobertura.datafile=${coberturaDataFile}"-->
    </containerset>
    
    <!-- define the formatter -->
    <formatter type="brief" usefile="false"/>
    <formatter type="xml"/>
    
    <!-- setup for batch-testing -->
    <batchtest fork="yes" todir="${unitTestResultsDir}">
      <fileset dir="${buildDir}/Cactus">
		<include name="**/*.class"/>
	  </fileset>
    </batchtest>   
  </cactus>   
    
    <fail if="tests.failed">
      tests.failed=${tests.failed}
    </fail>
    
    <!-- Generate the JUnit reports -->

        <junitreport todir="${unitTestResultsDir}/cactus">
            <fileset dir="${unitTestResultsDir}/cactus"
                 includes="TEST-*.xml"/>
            <report todir="${unitTestResultsDir}/cactus"
                format="frames"/>
        </junitreport>

    
  </target>
  
  <!-- Generate code coverage report-->
  <target name="code-coverage-report">
    <delete dir="${codeCoverageReportDir}"/>
    <cobertura-report format="html" datafile="${coberturaDataFile}"
destdir="${codeCoverageReportDir}">
      <fileset dir="${srcJavaDir}">
        <include name="**/*.java"/>
        <exclude name="**/*Test.java"/>
        <exclude name="**/test/*"/>
      </fileset>
      
    </cobertura-report>
     
  </target>

  

</project>



Still trying to get the maven plugin work.

Posted by Carlos de Luna Saenz <cd...@yahoo.com.mx>.
After several modifications i think i have my classes almost ready to be tested.
  Whe i ask for the maven cactus:cactifywar i got this warning:
  war:war:
    [echo] Building WAR infraestructura-paginacion
      [cactifywar] Analyzing war: C:\VSS\SVN\desarrollo\trunk\infraestructura\pagi
nacion\target\infraestructura-paginacion.war
    [cactifywar] Building war: C:\VSS\SVN\desarrollo\trunk\infraestructura\pagin
acion\target\infraestructura-paginacion-cactus.war
    [cactifywar] Warning: selected war files include a WEB-INF/web.xml which wil
l be ignored (please use webxml attribute to war task)
BUILD SUCCESSFUL
Total time: 33 seconds
Finished at: Mon May 08 14:03:03 CDT 2006

  when i run the tests via eclipse i got the following trace 
  javax.servlet.ServletException: Error finding class [mx.gob.imss.cia.infraestructura.paginacion.TestGridPaginadoTag] using both the Context classloader and the webapp classloader. Possible causes include:
 - Your webapp does not include your test classes,
 - The cactus.jar is not located in your WEB-INF/lib directory and your Container has not set the Context classloader to point to the webapp one
 at org.apache.cactus.internal.server.AbstractWebTestCaller.getTestClassClass(AbstractWebTestCaller.java:501)
 at org.apache.cactus.internal.server.AbstractWebTestCaller.getTestClassInstance(AbstractWebTestCaller.java:384)
 at org.apache.cactus.internal.server.AbstractWebTestCaller.doTest(AbstractWebTestCaller.java:109)
 at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody0(AbstractWebTestController.java:93)
 at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody1$advice(AbstractWebTestController.java:217)
 at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest(AbstractWebTestController.java)
 at org.apache.cactus.server.JspTestRedirector.doGet_aroundBody0(JspTestRedirector.java:70)
 at org.apache.cactus.server.JspTestRedirector.doGet_aroundBody1$advice(JspTestRedirector.java:217)
 at org.apache.cactus.server.JspTestRedirector.doGet(JspTestRedirector.java)
 at jsp_servlet.__jspredirector._jspService(__jspredirector.java:145)
 at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)
 at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:996)
 at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:419)
 at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:315)
 at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6456)
 at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
 at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
 at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3661)
 at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2630)
 at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219)
 at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)
   
  heres my cactus.properties file:
  cactus.home.weblogic7x=C:\bea\weblogic81
  cactus.weblogic7x.beahome=C:\bea
  cactus.contextURL=http://localhost:7001/infraestructura-paginacion-cactus/
  cactus.src.dir=src/test
  cactus.src.mergewebxml=src/test/webapp/WEB-INF/web.xml
  cactus.resources.dirs=src/test/webapp/WEB-INF
  cactus.port=7001
  cactus.compile.src.set=src/test/java/**/*.java
   
   
  maven.cactus.test.skip=false
  maven.test.skip=true
   
  Thanks in advance 
  Carlos de Luna Saenz

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
Regístrate ya - http://correo.espanol.yahoo.com/