如何使Sonar忽略codeCoverage指标的一些类? [英] How to make Sonar ignore some classes for codeCoverage metric?

查看:217
本文介绍了如何使Sonar忽略codeCoverage指标的一些类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Maven有一个Sonar个人资料。除代码覆盖率指标外,一切正常。我想让Sonar只为代码覆盖率指标忽略一些类。我有以下资料:

I have a Sonar profile in Maven. Everything works fine except the code coverage metric. I want to make Sonar ignore some classes only for the code coverage metric. I have the following profile:

<profile>
    <id>sonar</id>
    <properties>
        <sonar.exclusions>**/beans/jaxb/**</sonar.exclusions>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${maven.surefire.plugin.version}</version>
                <configuration>
                    <redirectTestOutputToFile>true</redirectTestOutputToFile>
                    <excludes>
                        <exclude>**/*Suite*.java</exclude>
                        <exclude>**/*RemoteTest.java</exclude>
                        <exclude>**/*SpringTest.java</exclude>
                        <exclude>**/*CamelTest.java</exclude>
                        <exclude>**/*FunctionalTest.java</exclude>
                        <exclude>**/*IntegrationTest.java</exclude>
                        <exclude>**/*DaoBeanTest.java</exclude>
                    </excludes>
                </configuration>
            </plugin>                    
        </plugins>
    </build>
</profile>

请帮助。我尝试添加类似

Please help. I tried to add something like

<exclude>com/qwerty/dw/publisher/Main.class</exclude>

但它没有帮助

更新

我有一个正确的Cobertura个人资料。我试图将它添加到Sonar配置文件中,但我仍然有53%而不是95%喜欢Cobertura配置文件

I have a correct Cobertura profile. I tried to add it to the Sonar profile, but still I have 53% instead about 95% like in the Cobertura profile

<profile>
    <id>sonar</id>
    <properties>
        <sonar.exclusions>**/beans/jaxb/**</sonar.exclusions>
        <sonar.core.codeCoveragePlugin>cobertura</sonar.core.codeCoveragePlugin>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${maven.surefire.plugin.version}</version>
                <configuration>
                    <redirectTestOutputToFile>true</redirectTestOutputToFile>
                    <excludes>
                        <exclude>**/*Suite*.java</exclude>
                        <exclude>**/*RemoteTest.java</exclude>
                        <exclude>**/*SpringTest.java</exclude>
                        <exclude>**/*CamelTest.java</exclude>
                        <exclude>**/*FunctionalTest.java</exclude>
                        <exclude>**/*IntegrationTest.java</exclude>
                        <exclude>**/*DaoBeanTest.java</exclude>
                    </excludes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <version>${cobertura.maven.plugin.version}</version>
                <configuration>
                    <instrumentation>
                        <excludes>
                            <exclude>com/qwerty/dw/dao/*</exclude>
                            <exclude>com/qwerty/dw/domain/*</exclude>
                            <exclude>com/qwerty/dw/beans/**/*</exclude>
                            <exclude>com/qwerty/dw/daemon/exception/*</exclude>
                            <exclude>com/qwerty/dw/daemon/Main.class</exclude>
                            <exclude>com/qwerty/dw/sink/Main.class</exclude>
                            <exclude>com/qwerty/dw/publisher/Main.class</exclude>
                            <exclude>com/qwerty/dw/publisher/dao/*</exclude>
                            <exclude>com/qwerty/dw/publisher/domain/*</exclude>
                        </excludes>
                    </instrumentation>
                    <formats>
                        <format>html</format>
                    </formats>
                    <aggregate>true</aggregate>
                    <check>
                        <haltOnFailure>true</haltOnFailure>
                        <branchRate>60</branchRate>
                        <lineRate>60</lineRate>
                        <totalBranchRate>60</totalBranchRate>
                        <totalLineRate>60</totalLineRate>
                    </check>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>clean</goal>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</profile>


推荐答案

在撰写本文时(与SonarQube一起) 4.5.1),要设置的正确属性是 sonar.coverage.exclusions ,例如:

At the time of this writing (which is with SonarQube 4.5.1), the correct property to set is sonar.coverage.exclusions, e.g.:

<properties>
    <sonar.coverage.exclusions>foo/**/*,**/bar/*</sonar.coverage.exclusions>
</properties>

这似乎是前几个版本的变化。请注意,这仅从覆盖率计算中排除给定的类。计算所有其他指标和问题。

This seems to be a change from just a few versions earlier. Note that this excludes the given classes from coverage calculation only. All other metrics and issues are calculated.

为了找到您的SonarQube版本的属性名称,您可以尝试转到常规设置您的SonarQube实例的部分,并查找代码覆盖率项目(在SonarQube 4.5.x中,即常规设置→排除→代码覆盖率)。在输入字段下方,它给出了上面提到的属性名称(Key:sonar.coverage.exclusions)。

In order to find the property name for your version of SonarQube, you can try going to the General Settings section of your SonarQube instance and look for the Code Coverage item (in SonarQube 4.5.x, that's General Settings → Exclusions → Code Coverage). Below the input field, it gives the property name mentioned above ("Key: sonar.coverage.exclusions").

这篇关于如何使Sonar忽略codeCoverage指标的一些类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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