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

forkMode is ignored when generating cobertura reports using Maven 3

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.5.1
    • Labels:
      None
    • Environment:
      Maven 3, Windows
    • Number of attachments :
      0

      Description

      I am evaluating upgrading my projects to use Maven 3.x, and I started to notice that some of my unit tests are failing when run as part of Cobertura, even though the same tests would pass without issues when they run under the regular "test" or "surefire" phases. It turns out that some of my tests have some depend on some static setup, so they would require to be run in separate JVMs, and this is usually accomplished by using <forkMode>always</forkMode> as part of the configuration of the surefire plugin. This worked fine with earlier versions of Maven, but started to break when trying Maven 3.x.

      To verify the issue, I ran the same "mvn site" command twice on the same POM, with different versions of Maven, and here is what I found out:

      • When using Maven 2.2.1, I can see that starting a new test will result in spawning a new JVM (I verified that using ProcessExplorer).
      • When using Maven 3.0, I can see that the same JVM is being reused across the different unit tests.

      Here are some of the relevant snippets from my POM:
      <!-- from the build part -->
      <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>2.6</version>
      <configuration>
      <forkMode>always</forkMode>
      <redirectTestOutputToFile>true</redirectTestOutputToFile>
      <includes>
      <include>**/*Test.java</include>
      </includes>
      </configuration>
      </plugin>

      <!-- from the reporting part -->
      <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-report-plugin</artifactId>
      <version>2.6</version>
      </plugin>
      <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>cobertura-maven-plugin</artifactId>
      <version>2.4</version>
      <configuration>
      <formats>
      <format>html</format>
      <format>xml</format>
      </formats>
      </configuration>
      </plugin>

      I suspect that this has to do with the way the surefire plugin is being called from Cobertura.

        Activity

        Hide
        gontard added a comment -

        I have the same problem. The fork configuration works with maven 2.2.1 but not with maven 3.0.

        Show
        gontard added a comment - I have the same problem. The fork configuration works with maven 2.2.1 but not with maven 3.0.
        Hide
        Nicolás G. Navarrete added a comment -

        same with maven 3.0.2

        Show
        Nicolás G. Navarrete added a comment - same with maven 3.0.2
        Hide
        Patricio Echague added a comment -

        Running into the same issue:
        Maven version: Apache Maven 3.0.2 (r1056850; 2011-01-08 16:58:10-0800)
        MAc OS X: 10.6.x

        Cobertura seems to ignore the fork mode in surefire and my tests fail on cobertura but do not fail with "mvn test".

        Show
        Patricio Echague added a comment - Running into the same issue: Maven version: Apache Maven 3.0.2 (r1056850; 2011-01-08 16:58:10-0800) MAc OS X: 10.6.x Cobertura seems to ignore the fork mode in surefire and my tests fail on cobertura but do not fail with "mvn test".
        Hide
        Benson Margulies added a comment -

        All cobertura does is ask for a parallel lifecycle to run tests.

        Show
        Benson Margulies added a comment - All cobertura does is ask for a parallel lifecycle to run tests.
        Hide
        Benson Margulies added a comment -

        The cobertura plugin tries to force forkMode to 'once' in its lifecycle.xml. It looks as if the M3 change might be that M3 changed maven so that the setting in the lifecycle.xml is honored. The question in my mind is, 'why is this in here at all'?

        Show
        Benson Margulies added a comment - The cobertura plugin tries to force forkMode to 'once' in its lifecycle.xml. It looks as if the M3 change might be that M3 changed maven so that the setting in the lifecycle.xml is honored. The question in my mind is, 'why is this in here at all'?
        Hide
        Patricio Echague added a comment -

        Benson, what is the change we should do to make cobertura work with M3 ?

        Show
        Patricio Echague added a comment - Benson, what is the change we should do to make cobertura work with M3 ?
        Hide
        Benson Margulies added a comment -

        I removed the forcing of forkMode when I closed this, and I tested the use of forkMode, at least somewhat. If it is still not working for you, please post a test case?

        Show
        Benson Margulies added a comment - I removed the forcing of forkMode when I closed this, and I tested the use of forkMode, at least somewhat. If it is still not working for you, please post a test case?
        Hide
        Patricio Echague added a comment -

        when should it be available in maven central?

        Show
        Patricio Echague added a comment - when should it be available in maven central?
        Hide
        Benson Margulies added a comment -

        There is a vote running now to release 2.5.1.

        Show
        Benson Margulies added a comment - There is a vote running now to release 2.5.1.

          People

          • Assignee:
            Benson Margulies
            Reporter:
            Firass Shehadeh
          • Votes:
            4 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: