views:

223

answers:

2

Hello, I am using eclipse + maven2 to build my applications. I need to start working with clover.

My question is therefore: from your experience, what is the best way to combine these 3.

I mean, I know there is a clover plugin for eclipse, there is also a clover plugin for maven2 and of course there is maven plugin for eclipse (m2eclipse - which I am already using).

What should I use and how?

Thank you.

+1  A: 

I'm using the clover-report along with the automated site generation by maven. For that you just have to add the clover plugin to your POMs reporting section as describes here. That way you can also get a historical report about your code coverage.

Calling/starting the maven process is done via the m2eclipse plugin and that's it. But you could also use all 3 plugins. So for example install the clover plugin for eclipse so that you don't have to generate the whole site again and again when you only want the code coverage (with the clover plugin for eclipse you can see the coverage right inside eclipse) and use the clover maven plugin to generate a "final" code coverage for any released piece of code. The m2eclipse plugin is not really needed for neither clover-maven nor clover-eclipse but it's nice when working with eclipse and maven.

seb
+4  A: 

Under Eclipse, use the Clover Eclipse Plugin.

Under Maven, use the Maven Clover Plugin. Add a Clover Report to the site generation:

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>com.atlassian.maven.plugins</groupId>
        <artifactId>maven-clover2-plugin</artifactId>
        <configuration>
          [...]
        </configuration>
        <executions>
          <execution>
            <phase>pre-site</phase>
            <goals>
              <goal>instrument</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
  <reporting>
    <plugins>
      [...]
      <plugin>
        <groupId>com.atlassian.maven.plugins</groupId>
        <artifactId>maven-clover2-plugin</artifactId>
        <configuration>
          [...]
        </configuration>
      </plugin>
    </plugins>
  </reporting>
[...]

Optionally, you can check for a test coverage percentage and fail the build in case of non-compliance:

  <build>
    <plugins>
      <plugin>
        <groupId>com.atlassian.maven.plugins</groupId>
        <artifactId>maven-clover2-plugin</artifactId>
        <configuration>
          <targetPercentage>80%</targetPercentage>
        </configuration>
        <executions>
          <execution>
            <phase>verify</phase>
            <goals>
              <goal>instrument</goal>
              <goal>check</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

The maven build remains the master. Run it using your preferred method (command line or m2eclipse).

Pascal Thivent
Do you happen to know of any other plugin doing the coverage check but not requiring a license for commercial projects?
zilupe
@Zilupe Have a look at [Cobertura](http://cobertura.sourceforge.net/).
Pascal Thivent
Thanks! Getting it to work was harder than Clover, but still manageable.
zilupe