【问题标题】:IT code coverage with sonar使用声纳覆盖 IT 代码
【发布时间】:2016-06-23 19:15:39
【问题描述】:

我手头有以下任务:

-- 查找项目的 IT 代码覆盖率

给定情况:

-- IT 代码位于与实际生产代码分开的存储库中

-- 为其创建测试的生产代码驻留在多个 git 存储库中。

--以上都是用maven,用Java写的。

我尝试了不同的教程和博客,但找不到更简单的答案。

谁能给我指出正确的资源或给我提示以启动?

【问题讨论】:

标签: maven sonarqube integration-testing jacoco


【解决方案1】:

我会尽量回答。我将发布带有 UT 的示例(IT 是同一件事,只是不在 maven livecycle 构建中的同一位置,而不是 surefire 插件,它是故障安全插件)

假设我们使用 JaCoCo 作为代码覆盖代理。 在我的父 pom 中,在配置文件部分(它是一个多模块项目)

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.15</version>
                    <configuration>
                        <argLine>${surefireArgLine}</argLine>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>0.7.4.201502262128</version>
                    <executions>
                        <execution>
                            <id>pre-unit-test</id>
                            <goals>
                                <goal>prepare-agent</goal>
                            </goals>
                            <configuration>
                                <destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile>
                                <propertyName>surefireArgLine</propertyName>
                            </configuration>
                        </execution>
                        <execution>
                            <id>post-unit-test</id>
                            <phase>test</phase>
                            <goals>
                                <goal>report</goal>
                            </goals>
                            <configuration>
                                <dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile>
                                <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

现在,当我们构建我们的 maven 项目时,我们添加配置文件以注入 JaCoCo 代理

clean install -Psonar-coverage 

然后我们可以告诉声纳分析我们的项目并通过以下命令使用 JaCoCo 报告

mvn org.codehaus.mojo:sonar-maven-plugin:2.4:sonar -Dsonar.dynamicAnalysis=reuseReports -Dsonar.java.coveragePlugin=jacoco -Dsonar.forceAnalysis=true -Dsonar.jacoco.reportMissing.force.zero=true -Dsonar.binaries=target/classes -Dsonar.junit.reportsPath=target/surefire-reports -Dsonar.jacoco.reportPath=target/coverage-reports/jacoco-ut.exec -Dsonar.jdbc.driver=com.mysql.jdbc.Driver -Dsonar.jdbc.url=jdbc:<YOUR SONAR INSTALLATION DB> -Dsonar.host.url=<YOUR SONAR INSTALLATION>

【讨论】:

    猜你喜欢
    • 2013-11-21
    • 2016-10-19
    • 2012-09-04
    • 2012-09-30
    • 1970-01-01
    • 2018-08-22
    • 2014-05-03
    • 1970-01-01
    • 2019-11-23
    相关资源
    最近更新 更多