java - Get correct coverage in sonar for unit and integration tests in separate maven modules -


my project setup simple (all source available @ github):

parent
↳ backend
↳ client
↳ integration-tests

and after runing maven:

mci sonar:sonar -dsonar.host.url=http://localhost:9000 -dsonar.login=12...9 

i see unit , integration tests visible sonar, coverage not. sonar coverage sonar coverage detailed

for intelij idea jacoco-it.exec looks fine: idea coverage

i'm assuming culprit here:

[info] sensor jacocosensor [java] [info] no jacoco analysis of project coverage can done since there no class files. [info] sensor jacocosensor [java] (done) | time=1ms 

so did small hack (in short: copied source files integration-test module):

    <properties>         <sonar.sources>${basedir}/target/copied</sonar.sources>     </properties>     [...]         <!-- hack generate coverage reports -->         <plugin>             <artifactid>maven-resources-plugin</artifactid>             <version>${maven-resources-plugin.version}</version>             <executions>                 <execution>                     <id>copy-resources</id>                     <phase>generate-sources</phase>                     <goals>                         <goal>copy-resources</goal>                     </goals>                     <configuration>                         <outputdirectory>${sonar.sources}</outputdirectory>                         <resources>                             <resource>                                 <directory>${basedir}/../backend/src/main/java</directory>                                 <filtering>false</filtering>                             </resource>                         </resources>                     </configuration>                 </execution>             </executions>         </plugin>         <plugin>             <groupid>org.codehaus.mojo</groupid>             <artifactid>build-helper-maven-plugin</artifactid>             <executions>                 <execution>                     <phase>generate-sources</phase>                     <goals>                         <goal>add-source</goal>                     </goals>                     <configuration>                         <sources>                             <source>${sonar.sources}</source>                         </sources>                     </configuration>                 </execution>             </executions>         </plugin> 

but classes ale duplicated (sonar shows classes ../target/copied dir): sonar coverage duplicated

sonar version: 6.5
jacoco maven plugin: 0.7.5.201505241946 (also tried lastest 0.7.9)

any ideas should here?

looks have answer question:

  1. report wasn't generated because post-unit-test execution in rong phase, instead of <phase>test</phase> have <phase>verify</phase>

  2. i had wrong goal post-integration-test. , change <goal>report-integration</goal> <goal>report-aggregate</goal>

  3. added properties: <jacoco.itreportpath>${project.basedir}/../integrations-tests/target/jacoco-it.exec</jacoco.itreportpath> , <sonar.jacoco.reportpaths>${jacoco.itreportpath},${project.build.directory}/jacoco-it.exec,${project.build.directory}/jacoco.exec</sonar.jacoco.reportpaths>

all chages , update project available on github


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -