通过Jacoco Agent进行集成测试的覆盖范围

时间:2015-03-01 13:30:32

标签: integration-testing jacoco jacoco-maven-plugin

使用jacoco代理并获得测试覆盖率报告有很多答案。他们中的大多数都有一半的答案,我很困惑。

这是我想要做的: 1.我的Java应用程序正在某个远程服务器上运行。说IP - 192.168.17.7

  1. 集成测试在本地运行,具有与应用程序代码存储库不同的存储库。测试代码回购是基于maven的。
  2. 我使用以下命令运行测试: mvn -Denv = stage -Dmaven.test.failure.ignore = true -DsuiteFile = src / test / java / Smoke.xml test

    现在如何使用jacoco代理获取jacoco覆盖率报告。

1 个答案:

答案 0 :(得分:0)

这些是要添加的插件

<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>

添加此个人资料

<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>

在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>
然后试着告诉我。