Setting additional Clover source roots

We have separated our integration test code (src/integration-test/java) from our unit test code (src/test/java) and I have not been able to find a way to add a source root to enable the Maven clover2 plugin to instrument the test cases.  If possible, could an additional source root be configured so that the clover2 plugin will instrument it as well?  In this case, could the clover2 plugin be configured to instrument the code in the src/test/java and src/integration-test/java directories?

Thanks,
Brian 

3 answers

1 vote

Hello Brian, 

It's possible to configure include integration-test directory into Clover instrumentation and reports. Please follow this configuration steps to achieve such behavior:

  1. Firstly add integtarion-test sources to the project with build-helper-maven-plugin such as:

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>1.9.1</version>
        <executions>
            <execution>
                <id>add-test-source</id>
                <phase>validate</phase>
                <goals>
                    <goal>add-test-source</goal>
                </goals>
                <configuration>
                    <sources>
                        <source>src/integration-test/java</source>
                    </sources>
                </configuration>
            </execution>
        </executions>
    </plugin>
  2. Configure Clover instrumentation to run in any phase before compilation time, but after build-helper-maven-plugin, i.e:

    <plugin>
        <groupId>com.atlassian.maven.plugins</groupId>
        <artifactId>maven-clover2-plugin</artifactId>
        <version>4.0.4</version>
        <executions>
            <execution>
                <id>clover-instrument</id>
                <phase>generate-resources</phase>
                <goals>
                    <goal>setup</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
  3. You should be able to generate reports now with a command:

    mvn clean verify clover2:aggregate clover2:clover -DgenerateHtml=true

    Compilation and tests should run but Clover probably will be reporting integration test classes as application code instead of test code. In that case you could tweak Clover reports to manually specify test code classes: 

    1.  Please follow this instruction, and setup testsources in the following way:

      <fileset id="testFileset" dir="${projectDir}" casesensitive="yes">
          <include name="src/test/**/*.java"/>
          <include name="src/integration-test/**/*.java"/>
      </fileset>
      //clover-report node:
      <testsources refId="testFileset"/>

Let me know how it worked for you.

 

Best regards,

Grzegorz Lewandowski 

Hiya Grzegorz,

Thanks!  With your instructions I was able to add the integration tests as a source directory smile .  Related to this question is how to exclude the unit tests.  I have used the following to exclude the unit tests, but they are still being instrumented.

<excludes>
	<exclude>**/*Test.java</exclude>
</excludes>

Would you happen to know how the unit tests could be excluded?

I should have provided additional context, but our goal is to understand our coverage of integration tests and unit tests separately.

Thanks,
Brian 

0 votes

Hey, 

 

It's a little bit complicated than only excluding test sources from instrumentation.

Clover instruments test sources to gather per-test coverage. In your case, you want to run separately unit test and integration and generate separate reports from both execution times.

You may want to exclude test (unit and integration tests) sources depending on execution time in order not to include unwanted data in your reports (i.e for integration-tests report will show unit test classes as completely uncovered code).

 

I'm not sure which maven plugins are you using to run the testing, but assuming this it's the maven-surefire-plugin the following configuration should work:

 

<dependencies>
        <dependency>
            <groupId>com.atlassian.clover</groupId>
            <artifactId>clover</artifactId>
            <version>4.0.5</version>
        </dependency>
    </dependencies>


    <build>
        <plugins>
            <plugin>  <!--ADDING IT TEST SOURCES TO COMPILATION ROOTS-->
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>1.9.1</version>
                <executions>
                    <execution>
                        <id>add-test-source</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>add-test-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>src/integration-test/java</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin> <!--CONFIGURING EXECUTION TIME FOR CLOVER2:SETUP-->
                <groupId>com.atlassian.maven.plugins</groupId>
                <artifactId>maven-clover2-plugin</artifactId>
                <version>4.0.5</version>
                <executions>
                    <execution>
                        <id>clover-instrument</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>setup</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>
    <profiles>
        <profile>
            <id>integration-test-profile</id> 
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <excludes> <!-- THERE'S NO NEED FOR INSTRUMENTING UNIT TESTS -->
                                <exclude>test/**/*.java</exclude>
                            </excludes>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>com.atlassian.maven.plugins</groupId>
                        <artifactId>maven-clover2-plugin</artifactId>
                        <configuration>
                            <excludes>
                                <exclude>test/**/*Test.java</exclude> <!-- INTEGRATION TESTS ONLY -->
                            </excludes>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>unit-test-profile</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <excludes> <!-- THERE'S NO NEED FOR INTEGRATION TESTS -->
                                <exclude>it/**/*.java</exclude> 
                            </excludes>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>com.atlassian.maven.plugins</groupId>
                        <artifactId>maven-clover2-plugin</artifactId>
                        <configuration>
                            <excludes>
                                <exclude>it/**/*Test.java</exclude> <!-- UNIT TESTS ONLY -->
                            </excludes>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

 

With given configuration you should be able to generate reports separately with the following commands:

  • for unit tests: 
    mvn clean verify clover2:aggregate clover2:clover -DgenerateHtml=true  -Dmaven.clover.reportDescriptor=clover-report.xml -P unit-test-profile
  • for integration tests:
    mvn clean verify clover2:aggregate clover2:clover -DgenerateHtml=true  -Dmaven.clover.reportDescriptor=clover-report.xml -P integration-test-profile

Assuming you've configured clover report descriptor as described in my previous comment. 

Please, let me know if you'll have any problems with this configuration.

 

Cheers,

Grzegorz Lewandowski 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published an hour ago in Jira Ops

Jira Ops Early Access Program Update #2: Let’s talk severity levels

Welcome to your weekly Jira Ops Early access program update, where we’re sharing news and updates on Jira Ops' progress as we work toward our 1.0 release. If you ever want to drop us feedback or idea...

10 views 0 0
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you