0

There are large number of answers to use jacoco agent and get test coverage report. Most of them has half answers and I am little confused.

Here is what I want to do: 1. My Java application is running on some remote server. say IP - 192.168.17.7

  1. Integration Tests are running on local with different repository from application code repo. Test code repo is maven based.

I run the tests with following command: mvn -Denv=stage -Dmaven.test.failure.ignore=true -DsuiteFile=src/test/java/Smoke.xml test

Now how do I get jacoco coverage report by using jacoco agent.

user2874299
  • 81
  • 1
  • 1
  • 3

1 Answers1

0

these are the plgins to be added

<plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>2.18</version>
                        <executions>
                            <execution>
                                <id>run-unit-tests</id>
                                <goals>
                                    <goal>test</goal>
                                </goals>
                                <configuration>
                                    <skip>${skipUnitTests}</skip>
                                    <argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <version>2.18</version>
                        <executions>
                            <execution>
                                <id>run-integration-tests</id>
                                <goals>
                                    <goal>integration-test</goal>
                                    <goal>verify</goal>
                                </goals>
                                <configuration>
                                    <skip>${skipIntegrationTests}</skip>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

add this profile

<profile>
        <id>sonar-coverage</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>0.7.4.201502262128</version>
                    <configuration>
                        <append>true</append>
                    </configuration>
                    <executions>
                        <execution>
                            <id>agent-for-ut</id>
                            <goals>
                                <goal>prepare-agent</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>agent-for-it</id>
                            <goals>
                                <goal>prepare-agent-integration</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>jacoco-site</id>
                            <phase>verify</phase>
                            <goals>
                                <goal>report</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>

add properties also in pom.xml

<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <sonar.language>java</sonar.language>
        <sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
        <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
        <sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath>
    </properties>

then try and tell me.

TEDDY
  • 821
  • 10
  • 24