From: John W. L. <Joh...@sa...> - 2012-07-27 15:30:41
|
Hi Sakthi, First, your instrumentation command is writing to a "${reports.dir}/basic_coverage.ser" file, but the <junit> command sets net.sourceforge.cobertura.datafile to "${basedir}/cobertura.ser". Those need to be the same. Next, let me know if I am wrong, but it appears that the code you are trying to instrument is in jars. Therefore, you should see a jar (or more) in the ${instrumented.dir}. If not, then nothing is getting instrumented. In that case, you need to use this pattern: <cobertura-instrument todir="${instrumented.dir}"> <includeClasses regex=".*" /> <excludeClasses regex=".*\.Test.*" /> <instrumentationClasspath> <fileset dir="${jars.dir}"> <include name="**/*.jar" /> </fileset> </instrumentationClasspath> </cobertura-instrument> Feel free to use your <ignore regex="org.apache.log4j.*" /> in there as well. Next, since you are using jars, the classpath in your <junit> command needs to add the jars. Instead of just: <classpath location="${instrumented.dir}" /> You need: <classpath> <fileset dir="${instrumented.dir}"> <include name="**/*.jar" /> </fileset> </classpath> That should do it. Let me know if you have any problems with this. John From: *** From Sakthivel Kumar*** [mailto:nsa...@gm...] Sent: Thursday, July 26, 2012 1:03 AM To: John W. Lewis Cc: cob...@li... Subject: I do not see cobertura.ser file that is created during the instrumentation. John: As you mentioned in your below notes, after instrumentation, I fully searched my C drive, i do not see a cobertura.ser file that is created after code instrumentation is done. Below is the BuildInstument.Xml i used to for code instrumentation. Please take a look and let me know if something is wrong. Also provide me a sample working instrument build file that creates cobertura.ser file. I appreciate your help and time. Thanks in advance Sakthi <?xml version="1.0" encoding="UTF-8"?> <project name="cobertura.examples.basic" default="InstrumentQReads" basedir="."> <description> Cobertura - http://cobertura.sourceforge.net/ </description> <property file="build.properties" /> <!-- cobertura task definition --> <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"/> <target name="init"> <echo message="MHD: Inside ... init of InstrumentQReads..."/> <mkdir dir="${classes.dir}" /> <mkdir dir="${instrumented.dir}" /> <echo message="MHD: Done... init of InstrumentQReads."/> </target> <target name="compile" depends="init"> <echo message="MHD: Inside ... compile of InstrumentQReads..."/> <javac srcdir="${src.dir}" destdir="${classes.dir}" debug="true" debuglevel="vars,lines,source" > <classpath refid="cobertura.classpath" /> </javac> <echo message="MHD: Done... compile of InstrumentQReads..."/> </target> <target name="instrument" depends="init,compile" > <echo message="MHD: Doing instrumentation for jar files."/> <!-- Remove the coverage data file and any old instrumentation. --> <delete file="cobertura.ser"/> <!-- delete dir="${instrumented.dir}" / --> <!-- Instrument the application jars, writing the instrumented jars, in to ${build.instrumented.dir}. --> <cobertura-instrument datafile="${reports.dir}/basic_coverage.ser" todir="${instrumented.dir}"> <!-- The following line causes instrument to ignore any source line containing a reference to log4j, for the purposes of coverage reporting.--> <ignore regex="org.apache.log4j.*" /> <fileset dir="${jars.dir}"> <include name="**/*.jar" /> </fileset> </cobertura-instrument> <echo message="MHD: done instrumentation of jar Files."/> </target> <target name="test" depends="init,compile"> <junit fork="yes" dir="${basedir}" failureProperty="test.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="${basedir}/cobertura.ser" /> <!-- Note the classpath order: instrumented classes are before the original (uninstrumented) classes. This is important. --> <classpath location="${instrumented.dir}" /> <!-- The instrumented classes reference classes used by the Cobertura runtime, so Cobertura and its dependencies must be on your classpath. <classpath refid="cobertura_classpath" /> <formatter type="xml" /> <test name="${testcase}" todir="${reports.xml.dir}" if="testcase" /> <batchtest todir="${reports.xml.dir}" unless="testcase"> <fileset dir="${src.dir}"> <include name="**/*Test.java" /> </fileset> </batchtest> --> </junit> </target> <target name="InstrumentQReads" depends="instrument,compile,test" description="Compile and instrument QReads jar files."/> </project> On Thu, May 24, 2012 at 11:16 AM, John W. Lewis <Joh...@sa...<mailto:Joh...@sa...>> wrote: That almost always means that your tests are not using the cobertura.ser file that is created during the instrumentation. You have to make sure that the cobertura.ser file is moved to the working directory of your tests, or use the cobertura property (as described in the Cobertura Ant documentation) to point to the cobertura.ser file. From: Ionel Pagu [mailto:Ion...@te...<mailto:Ion...@te...>] Sent: Thursday, May 24, 2012 11:54 AM To: cob...@li...<mailto:cob...@li...> Subject: [Cobertura-devel] coverage not reported properly on the main page Hi, After tweaking the ant scripts a bit, I was now able to instrument, run our jUnits and then run the report successfully. However, there is one odd thing: in the main report page, the coverage is reported as 100% everywhere but I know our jUnits are not that good. Even further, if I click the links to check source code I can clearly see code not being (fully) covered. So now I am puzzled. The tools seems to detect that properly but not summarize it correctly. Any idea? Thanks, Ionel Pagu The information in this e-mail is confidential and may be legally privileged. It is intended solely for the addressee. Access to this e-mail by anyone else is unauthorized. ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Cobertura-devel mailing list Cob...@li...<mailto:Cob...@li...> https://lists.sourceforge.net/lists/listinfo/cobertura-devel -- Thanks and Best Regards Sakthivel Kumar nsa...@gm...<mailto:nsa...@gm...> |