1. Its good documentation, however i fail to understand how dataFile works.
    Does cobertura creates it or testng task creates it.
    I got the report but the coverage is 0. Can’t figure out how to get the coverage.
    My tests shows proper coverage using the eclipse plugin.
    Please help

    • The cobertura.ser data file is created by Cobertura and not by TestNG, it contains the instrumentation data about your tests as they are run. A coverage of 0 in the reports usually means the classpath is not configured correctly (i.e., cobertura cannot find the instrumented classes). Make sure you define the source (test classes) classpath and the target (source classes) correctly.

  2. still can’t figure out. Can you help me please
    One thing more to know. Another ant script runs first and places my source compiled jar file to /testlib.

  3. Sumit, a quick read through your code reveals some configuration issues, you are not defining the coverageDataFile correctly:

    Add the following to your configuration:

     <property key="cb.file" value="${basedir}/cobertura.ser" />  

    Change the net.sourceforge.cobertura.datafile property to:

     <sysproperty key="net.sourceforge.cobertura.datafile" file="${cb.file}" />  

    Change the “clean” target to:

    <delete file="${cb.file}" />  

    Change the “cb.instrument” target to:

    <cobertura-instrument todir="${cb.instrument.dir}/"  

    Do the same for the datafile attribute in your cb.xml and cb.html targets.

    I suspect cobertura instruments the code but cannot find the instrumentation file which why your getting 0 coverage.

  4. Akshat


    Will the above piece of XML will also help in instrumenting a JAR file as well. I have a JAR file for which I write tests in TestNG. I want to see how much Test coverage s done by my TestnG cases.

Leave a Reply

Your email address will not be published. Required fields are marked *