【问题标题】:integration coverage results not shown in sonar声纳中未显示集成覆盖结果
【发布时间】:2015-07-24 19:40:44
【问题描述】:

我正在尝试在我的声纳实例中获取集成测试统计信息。经过大量搜索,我仍然没有发现我做错了什么。我使用配置文件跳过(IT)测试,这似乎对我有用。

在 jenkins 中,我的声纳构建目标是

verify -P integration-test -Dsonar.phase=verify

对于我之前的集成测试构建

failsafe:integration-test -P integration-test

我有以下 pom.xml

<build>
<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
            <execution>
                <goals>
                    <goal>analyze</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
            <skipTests>${skipUnitTests}</skipTests>
        </configuration>
    </plugin>
    <!-- Run integration tests (*IT) -->
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <executions>
            <execution>
                <id>integration-test</id>
                <goals>
                    <goal>integration-test</goal>
                    <goal>verify</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <skipTests>${skipITTests}</skipTests>
            <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
            <argLine>${jacoco.agent.argLine}</argLine>
        </configuration>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-report-plugin</artifactId>
    </plugin>
    <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <executions>
            <execution>
                <id>jacoco-initialize</id>
                <goals>
                    <goal>prepare-agent</goal>
                </goals>
                <configuration>
                        <destfile>${project.build.directory}/jacoco.it.exec</destfile>
                    <datafile>${project.build.directory}/jacoco.it.exec</datafile>
                </configuration>
            </execution>
            <execution>
                <id>jacoco-site</id>
                <phase>package</phase>
                <goals>
                    <goal>report</goal>
                </goals>
                <configuration>
                    <destfile>${project.build.directory}/jacoco.it.exec</destfile>
                        <datafile>${project.build.directory}/jacoco.it.exec</datafile>
                </configuration>
            </execution>
            <execution>
                <id>pre-integration-test</id>
                <phase>pre-integration-test</phase>
                <goals>
                    <goal>prepare-agent-integration</goal>
                </goals>
                <configuration>
                    <destfile>${project.build.directory}/jacoco.it.exec</destfile>
                        <datafile>${project.build.directory}/jacoco.it.exec</datafile>
                </configuration>
            </execution>
            <execution>
                <id>post-integration-test</id>
                <phase>post-integration-test</phase>
                <goals>
                    <goal>report-integration</goal>
                </goals>
                <configuration>
                    <destfile>${project.build.directory}/jacoco.it.exec</destfile>
                        <datafile>${project.build.directory}/jacoco.it.exec</datafile>
                </configuration>
            </execution>
        </executions>
    </plugin>
</build>
<reporting>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-report-plugin</artifactId>
            <version>${maven-surefire-report-plugin.version}</version>
        </plugin>
    </plugins>
</reporting>
<profiles>
    <profile>
        <id>test</id>
        <activation>
            <activeByDefault>false</activeByDefault>
        </activation>
        <properties>
            <maven.test.skip>false</maven.test.skip>
            <skipUnitTests>false</skipUnitTests>
            <skipITTests>true</skipITTests>
            <maven.test.failure.ignore>false</maven.test.failure.ignore>
        </properties>
    </profile>
    <profile>
        <id>integration-test</id>
        <activation>
            <activeByDefault>false</activeByDefault>
        </activation>
        <properties>
            <maven.test.skip>false</maven.test.skip>
            <skipUnitTests>true</skipUnitTests>
            <skipITTests>false</skipITTests>
            <maven.test.failure.ignore>false</maven.test.failure.ignore>
        </properties>
    </profile>
    <profile>
        <id>sonar</id>
        <activation>
            <activeByDefault>false</activeByDefault>
        </activation>
        <properties>
            <maven.test.skip>false</maven.test.skip>
            <skipUnitTests>true</skipUnitTests>
            <skipITTests>false</skipITTests>
            <maven.test.failure.ignore>true</maven.test.failure.ignore>

            <sonar.jdbc.url>jdbc:mysql://sonar-url/sonar?useUnicode=true&amp;characterEncoding=utf8</sonar.jdbc.url>
            <sonar.jdbc.driverClassName>com.mysql.jdbc.Driver</sonar.jdbc.driverClassName>
            <sonar.jdbc.username>sonar</sonar.jdbc.username>
            <sonar.jdbc.password>sonar</sonar.jdbc.password>
            <sonar.host.url>http://sonar-url/</sonar.host.url>
            <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
            <sonar.junit.reportsPath>target/surefire-reports</sonar.junit.reportsPath>
            <sonar.jacoco.reportPath>target/jacoco.exec</sonar.jacoco.reportPath>
            <sonar.jacoco.itReportPath>target/jacoco.it.exec</sonar.jacoco.itReportPath>
            <sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>

            <!-- Sonar exclusions **/static/libs/*.js: third-party JavaScript libraries -->
            <!-- **/jquery*.js: third-party jQuery libraries -->
            <!-- src/main/webapp/static/styles/css/bootstrap/bootstrap*.css src/main/webapp/static/styles/css/bootstrap*.css 
                default Bootstrap CSS files -->
            <!-- (regular & minified) src/main/webapp/static/app/services/ogmSvc.js: angular service lib -->
            <sonar.exclusions>**/static/libs/*.js, **/jquery*.js,
                src/main/webapp/static/styles/css/bootstrap/bootstrap*.css,
                src/main/webapp/static/styles/css/bootstrap*.css,
                src/main/webapp/static/app/services/ogmSvc.js
            </sonar.exclusions>
        </properties>
    </profile>

谁能告诉我我做错了什么或忘记了什么?

谢谢

【问题讨论】:

  • 我认为这是因为您在 Maven 的 JVM 中运行非单元(集成)测试(因为运行 Maven 需要 Java)以及运行非单元测试(即集成/接受/Selenium等),您通常在远程 JVM 后面运行它(即 Tomcat 的 JVM,因为运行 Tomcat 需要它自己/单独的 JVM)。现在,您要做的是(我猜)将 jacocoagent.jar 附加到 Tomcat 的 JVM(即在启动 Tomcat 以扩展应用程序/项目的 .war 时)您必须告诉 Tomcat,这是 jacocoagent.jar 并且在这个位置我将创建 jacoco-it.exec 文件。
  • Tomcat 启动后,运行 IT 测试,停止 Tomcat,然后运行 ​​jacoco report。停止 tomcat 很重要,因为它会将数据刷新到 .exec 文件。 PS:eclemma.org/jacoco/trunk/doc/agent.htmleclemma.org/jacoco/trunk/doc/…
  • 目前,我只是在最后用 IT 重命名的 Junit 测试对其进行测试

标签: maven jenkins sonarqube jacoco surefire


【解决方案1】:

您可能已经这样做了,但不要忘记在您的声纳服务器中添加集成测试小部件。 (默认登录为 admin-admin)

【讨论】:

    【解决方案2】:

    问题是我配置了 jacoco 错误,因此报告的位置与声纳接收它们的位置不同。

    【讨论】:

      猜你喜欢
      • 2016-11-11
      • 2015-03-17
      • 2014-04-09
      • 2013-10-14
      • 2011-12-02
      • 2013-11-21
      • 2012-07-18
      • 2015-08-08
      • 2020-04-25
      相关资源
      最近更新 更多