Mojo's Cobertura Maven Plugin
  1. Mojo's Cobertura Maven Plugin
  2. MCOBERTURA-70

I must run 'mvn cobertura:cobertura' twice to get a valid coverage report.

    Details

    • Type: Bug Bug
    • Status: Open Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.1
    • Fix Version/s: None
    • Labels:
      None
    • Number of attachments :
      4

      Description

      Our nightly build does:
      'mvn clean'
      'mvn install'
      'mvn cobertura'
      'mvn site'
      We have found that for the last couple of months (or possibly more), our coverage reports are showing 0% coverage on all tests. I have found that we have to run 'mvn cobertura:cobertura' TWICE! to get a valid coverage report. What gives? Is there any workaround? I have tried all sorts of things but nothing really works.

      1. CoberturaDataUtil.java
        3 kB
        Martin Zeltner
      2. CoberturaReportMojo.java
        8 kB
        Martin Zeltner
      3. ConditionalSaveTimer.java
        3 kB
        Martin Zeltner
      4. ProjectData.java
        8 kB
        Martin Zeltner

        Issue Links

          Activity

          Hide
          Martin Zeltner added a comment -

          Hello

          Also with version 2.2 and forkMode the problem was still there.
          I have now patched cobertura itself and the maven plugin, so that it works fine.

          The problem was, that for saving the cobertura.ser file, just a shutdown hook was installed. The solution is to trigger cobertura to save the file additionally before the JVM ends. For that I added a new timer task in class ProjectData (see appended class =ConditionalSaveTimer=). Every half second the ConditionalSaveTimer checks if there is a directory "pleaseSaveCobertura" in the directory where the cobertura.ser is saved. If yes, cobertura saves. That is all we do in cobertura.

          In the maven plugin we must now create such a "trigger directory" to trigger cobertura to save. We execute the following line in method "executeReport":
          "CoberturaDataUtil.waitUntilDefaultCoberturaCoverageFileSecurelySaved(getLog());"
          See attached files "CoberturaReportMojo" and "CoberturaDataUtil"

          All jars are relased on EL4J's Maven 2 repo. Just use them!
          http://public-el4.elca-services.ch/el4j/maven2repository/

          <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>cobertura-maven-plugin</artifactId>
          <version>2.3-el4j_20100108_1400</version>
          </plugin>

          Do not forget the configure the plugin twice, in build AND reporting section of your pom!

          Because there are two report goals that does execute cobertura, do not forget to configure the reportSets:
          <reportSets>
          <reportSet>
          <id>standardReports</id>
          <reports>
          <report>cobertura</report>
          </reports>
          </reportSet>
          </reportSets>

          To complete the listing, here the cobertura dependency for your dependency management:
          <dependency>
          <groupId>net.sourceforge.cobertura</groupId>
          <artifactId>cobertura</artifactId>
          <version>1.9-el4j_20100108_1600</version>
          </dependency>

          BTW: To record the code coverage while working with the web or gui application, we have created another plugin. See http://el4j.sourceforge.net/plugins/maven-cobertura-runtime-plugin/index.html

          Cheers,
          Martin Zeltner
          http://el4j.sourceforge.net

          Show
          Martin Zeltner added a comment - Hello Also with version 2.2 and forkMode the problem was still there. I have now patched cobertura itself and the maven plugin, so that it works fine. The problem was, that for saving the cobertura.ser file, just a shutdown hook was installed. The solution is to trigger cobertura to save the file additionally before the JVM ends. For that I added a new timer task in class ProjectData (see appended class =ConditionalSaveTimer=). Every half second the ConditionalSaveTimer checks if there is a directory "pleaseSaveCobertura" in the directory where the cobertura.ser is saved. If yes, cobertura saves. That is all we do in cobertura. In the maven plugin we must now create such a "trigger directory" to trigger cobertura to save. We execute the following line in method "executeReport": "CoberturaDataUtil.waitUntilDefaultCoberturaCoverageFileSecurelySaved(getLog());" See attached files "CoberturaReportMojo" and "CoberturaDataUtil" All jars are relased on EL4J's Maven 2 repo. Just use them! http://public-el4.elca-services.ch/el4j/maven2repository/ <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <version>2.3-el4j_20100108_1400</version> </plugin> Do not forget the configure the plugin twice, in build AND reporting section of your pom! Because there are two report goals that does execute cobertura, do not forget to configure the reportSets: <reportSets> <reportSet> <id>standardReports</id> <reports> <report>cobertura</report> </reports> </reportSet> </reportSets> To complete the listing, here the cobertura dependency for your dependency management: <dependency> <groupId>net.sourceforge.cobertura</groupId> <artifactId>cobertura</artifactId> <version>1.9-el4j_20100108_1600</version> </dependency> BTW: To record the code coverage while working with the web or gui application, we have created another plugin. See http://el4j.sourceforge.net/plugins/maven-cobertura-runtime-plugin/index.html Cheers, Martin Zeltner http://el4j.sourceforge.net
          Hide
          Leeland Artra added a comment -

          This issue persists even in version 2.4 release. If anyone has it working such that a calling "mvn clean cobertura:cobertura" produces accurate coverage reports would you please post the relevant POM sections.

          I have found that running "mvn clean cobertura:cobertura" yeilds a coverage report of 0%, each subsequent run of just "mvn cobertura:cobtertura" adds the prior test set values to the test reports. So if a section of code is called 3 times the first pass after a clean is shown as 0, the second pass it is shown as 3, the third pass 6, and so on.

          Show
          Leeland Artra added a comment - This issue persists even in version 2.4 release. If anyone has it working such that a calling "mvn clean cobertura:cobertura" produces accurate coverage reports would you please post the relevant POM sections. I have found that running "mvn clean cobertura:cobertura" yeilds a coverage report of 0%, each subsequent run of just "mvn cobertura:cobtertura" adds the prior test set values to the test reports. So if a section of code is called 3 times the first pass after a clean is shown as 0, the second pass it is shown as 3, the third pass 6, and so on.
          Hide
          Lukas Theussl added a comment -

          2.4 works for me with forkMode=once as I posted above.

          Show
          Lukas Theussl added a comment - 2.4 works for me with forkMode=once as I posted above.
          Hide
          Atanu Panda added a comment -

          HI Friends,

          I have the same problem. I have found that though the unit tests have been run successfully, but code coverage is showing as 0%.

          Log message is attached below
          ===========
          .
          .
          Successful Testing.....
          tearDown.....
          Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 22.562 sec

          Results :

          Tests run: 3, Failures: 0, Errors: 0, Skipped: 0

          [INFO] [cobertura:cobertura

          {execution: default-cli}

          ]
          [INFO] Cobertura 1.9.2 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
          Cobertura: Loaded information on 103 classes.
          Report time: 8281ms

          [INFO] Cobertura Report generation was successful.
          [INFO] ------------------------------------------------------------------------
          [INFO] BUILD SUCCESSFUL
          .
          .
          ===========================

          My plugin configuration is as follows
          --------------------------

          <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.5</version>
          <configuration>
          <includes>
          <include>**/Test.java</include>
          </includes>
          </configuration>
          </plugin>

          <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>cobertura-maven-plugin</artifactId>
          <version>2.3</version>
          <configuration>
          <includes>
          <include>**/Test.java</include>
          </includes>
          <forkMode>once</forkMode>
          </configuration>
          </plugin>

          -------------------------------

          Please help me out. Please let me know if you need any other information.

          Thanks
          Atanu Panda

          Show
          Atanu Panda added a comment - HI Friends, I have the same problem. I have found that though the unit tests have been run successfully, but code coverage is showing as 0%. Log message is attached below =========== . . Successful Testing..... tearDown..... Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 22.562 sec Results : Tests run: 3, Failures: 0, Errors: 0, Skipped: 0 [INFO] [cobertura:cobertura {execution: default-cli} ] [INFO] Cobertura 1.9.2 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file Cobertura: Loaded information on 103 classes. Report time: 8281ms [INFO] Cobertura Report generation was successful. [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL . . =========================== My plugin configuration is as follows -------------------------- <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.5</version> <configuration> <includes> <include>**/ Test .java</include> </includes> </configuration> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <version>2.3</version> <configuration> <includes> <include>**/ Test .java</include> </includes> <forkMode>once</forkMode> </configuration> </plugin> ------------------------------- Please help me out. Please let me know if you need any other information. Thanks Atanu Panda
          Hide
          Lukas Theussl added a comment -

          The forkMode setting should go into the configuration of the surefire-plugin.

          Show
          Lukas Theussl added a comment - The forkMode setting should go into the configuration of the surefire-plugin.

            People

            • Assignee:
              Unassigned
              Reporter:
              Gary Kind
            • Votes:
              6 Vote for this issue
              Watchers:
              13 Start watching this issue

              Dates

              • Created:
                Updated: