声纳覆盖IT代码 [英] IT code coverage with sonar

查看:83
本文介绍了声纳覆盖IT代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我手头有以下任务:

-查找项目的IT代码覆盖范围

-- find IT code coverage for a project

鉴于情况:

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

-- IT code resides in a repository separate to the actual production code

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

-- Production code that the tests were created for reside in more than one git repository.

-上面所有方法都使用maven并用Java编写.

-- all of the above uses maven and are written in Java.

我尝试过以下教程和博客,但找不到简单的答案.

I have tried following different tutorial and blogs but couldnt find a simpler answer.

任何人都可以将我指向正确的资源,或者给我提示启动的机会吗?

Can anyone either point me towards the right resource or give me hints for a kick start?

推荐答案

我将尝试回答.我将用UT发布示例(IT是同一件事,只是不在Maven Livecycle构建中的同一位置,并且代替了surefire插件及其故障保护插件)

I will try to answer. I will post example with UT (IT is the same thing just not at the same place in the maven livecycle build, and instead of the surefire plugin its the failsafe plugin)

让我们说我们使用JaCoCo作为代码覆盖率代理. 在我的父pom的个人资料部分(这是一个多模块项目)中

Lets say we use JaCoCo for the code coverage agent. In my Parent pom, in the profile section (it is a multi module project)

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

Now when we build our maven project, we add the profile to inject the JaCoCo Agent

clean install -Psonar-coverage 

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

Then we may tell sonar to analyse our project and to use the JaCoCo report with the following command

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>

这篇关于声纳覆盖IT代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆