简体   繁体   English

未计算声纳覆盖范围

[英]Sonar coverage is not calculated

I am trying to integrate my code coverage into the sonar but it shows 0. I have integrated jacoco as below to my pom but, it still shows the code coverage as zero.我正在尝试将我的代码覆盖率集成到声纳中,但它显示为 0。我已将 jacoco 集成到我的 pom 中,但它仍然显示代码覆盖率为零。

I have only used the pom file from this repository, what other configuration should I work in order to have code coverage?我只使用了这个存储库中的 pom 文件,我应该使用哪些其他配置来覆盖代码?

What would be other parameters should I possibly add?我应该添加哪些其他参数?

https://github.com/daniel-frak/keycloak-user-migration/blob/master/pom.xml https://github.com/daniel-frak/keycloak-user-migration/blob/master/pom.xml

Thanks.谢谢。

Full repo:完整回购:

https://github.com/daniel-frak/keycloak-user-migration https://github.com/daniel-frak/keycloak-user-migration

There are a number of things that can cause this.有很多事情会导致这种情况。

The first thing you should do is examine the workspace to see if the Jacoco plugin wrote its output files anywhere in the "target" tree.您应该做的第一件事是检查工作区,看看 Jacoco 插件是否将其 output 文件写入“目标”树中的任何位置。 It will generate a data file in one or more formats, but it will also generate an html tree, with an "index.html" in the root.它将生成一种或多种格式的数据文件,但它还会生成一个 html 树,根目录中有一个“index.html”。 You can visit that file, and it will show your coverage results.您可以访问该文件,它将显示您的覆盖结果。

If you don't find those files, then either your jacoco plugin is not properly integrated with your surefire plugin, or you simply didn't run your unit tests in the build (don't laugh, I've seen people do this).如果你没有找到这些文件,那么要么你的 jacoco 插件没有与你的 surefire 插件正确集成,要么你根本没有在构建中运行你的单元测试(别笑,我见过有人这样做) .

The "integration" is done by telling Jacoco what variable to put the required command line into, and telling Surefire to use that variable. “集成”是通过告诉 Jacoco 将所需命令行放入哪个变量,并告诉 Surefire 使用该变量来完成的。

Here is a sample jacoco plugin definition:这是一个示例 jacoco 插件定义:

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>${jacoco.maven.plugin.version}</version>
    <executions>
        <execution>
            <id>pre-unit-test</id>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
            <configuration>
                <propertyName>surefireArgLine</propertyName>
            </configuration>
        </execution>
        <execution>
            <id>post-unit-test</id>
            <phase>test</phase>
            <goals>
                <goal>report</goal>
            </goals>
            <configuration>
                <outputDirectory>${jacoco.path}</outputDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>

Note the reference to "surefireArgLine".注意对“surefireArgLine”的引用。 Here is the Surefire definition that goes with that:这是 Surefire 的定义:

<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>${maven.surefire.plugin.version}</version>
    <configuration>
        <argLine>${surefireArgLine}</argLine>
    </configuration>
</plugin>

We also combine this with these property settings:我们还将其与这些属性设置相结合:

    <jacoco.path>${basedir}/target/jacoco_report</jacoco.path>
    <sonar.coverage.jacoco.xmlReportPaths>${basedir}/target/jacoco_report/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM