0
votes

I've a pretty standard Java-Maven build with some plain JUnit tests and some for Arquillian. JaCoCo is hooked via Maven like this:

    <properties>
        <sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath>
    </properties>

<pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <argLine>${argLine}</argLine>
            </configuration>
        </plugin>
    </plugins>
</pluginManagement>

<plugins>
    <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>0.8.4</version>
        <configuration>
            <destFile>${sonar.jacoco.reportPath}</destFile>
            <append>true</append>
        </configuration>
        <executions>
            <execution>
                <id>agent</id>
                <goals>
                    <goal>prepare-agent</goal>
                </goals>
            </execution>
            <execution>
                <id>report</id>
                <phase>test</phase>
                <goals>
                    <goal>report</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
</plugins>

Running Sonar now seems to work, however the code coverage is all wrong. I'm not sure if these are separate issues or if there is one problem with the configuration producing all of them, so I'll just list them:

  • test suites are not run at all (meaning JUnit tests with @RunWith(AllTests.class))
  • Arquillian tests (with @RunWith(Arquillian.class)) are run, but the code coverage is wrong, i.e. entities have a code coverage of 0%
  • an entire module is not tested and I'm not sure why (all but one of the tests has @RunWith(Parameterized.class), but this annotation works in another module)

(After Qword's suggestion I tried it without the reportPath. However the reports in target/sites/jacoco/ are still missing the coverage.)

I'm wondering if the problem is with the JUnit runners or maybe because some of these tests are in another module than the classes they test (Arquillian / integration tests especially). On the other hand, some of the JUnit runners seem to work as well. Maybe it's a third component that breaks the build.

I tried arquillian-extension-jacoco as well, this plug-in doesn't seem to work at all (tests won't even start).

Is the problem with the JUnit runners? With the integration tests? How do I fix this?

1

1 Answers

-2
votes

You don't actually need to specify sonar.jacoco.reportPath. First of all, it's been deprecated in favor of sonar.jacoco.reportPaths. Second, if you specify the latter property, all reports will be created in a single binary file, but this is not default Jacoco behaviour (and SonarQube deprecated that as well).

I would suggest, as a first step, to

  • Entirely remove properties sonar.jacoco.reportPath and sonar.jacoco.reportPaths
  • Remove the configuration node from Jacoco plugin definition

Now, you'll won't find anymore the jacoco.exec file but instead for every module you'll find a new directory target/sites/jacoco in which there will be reports in CSV, XLM, and HTML. This is the standard Jacoco behaviour in v0.8.4.

I'm not entirely sure this will fix all your problems, but at least

  • I'm quite sure SonarQube will be able to correctly pick up the reports and show the coverage
  • You'll be able to analyse coverage with a simple mvn clean install on your local machine without having to go to SonarQube every time