简体   繁体   English

我的Jacoco报告显示的代码覆盖率很小

[英]My Jacoco report is showing very little code coverage

I am trying to get an idea of how much code coverage I have with some unit tests in Scala and with the source code in Java(tests and code are in different packages). 我试图弄清楚我在Scala中的一些单元测试和Java中的源代码有多少代码覆盖率(测试和代码在不同的包中)。 When I run the Jacoco report, it is showing only 4 percent code coverage. 当我运行Jacoco报告时,它仅显示4%的代码覆盖率。

When I go take a look at the report, it shows 0 percent for a lot of files that I have created tests for. 当我查看该报告时,对于我为其创建测试的许多文件,它显示为0%。 What I suspect is that the unit tests are not being included in the report, maybe since all of the test class files are in the target/test-classes directory. 我怀疑是因为报告中没有包含单元测试,可能是因为所有测试类文件都位于target / test-classes目录中。 I have tried including the includeTests tag but that didn't have any effect. 我尝试过包括includeTests标记,但这没有任何效果。

Here is how the plugin looks like in the pom: 这是插件在pom中的外观:

<plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>${jacoco-maven-plugin.version}</version>
                    <configuration>
                        <includeTests>true</includeTests>
                        <!--<includes>
                            <include>**/test-classes/**</include>
                        </includes>-->
                        <excludes>
                            <exclude>**/dto/**</exclude>
                            <exclude>**/exceptions/**</exclude>
                        </excludes>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>prepare-agent</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>report</id>
                            <phase>prepare-package</phase>
                            <goals>
                                <goal>report</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

Right now I have commentted out the include tag becasue if I include it, the test compiles with 0 classes. 现在,由于include标记,因此我已将其注释掉,因为如果将其包含在内,则该测试将使用0个类进行编译。 How else can I can include the target/test-classes directory? 我还能如何包含target / test-classes目录?

Sorry if this is a simple fix, I'm very new with unit testing and Jacoco. 抱歉,如果这是一个简单的修复程序,那么我对单元测试和Jacoco还是陌生的。 Thanks! 谢谢!

This is my personal setup. 这是我的个人设置。 It's a bit messy and I'm still working out some parts of it but it works for me. 有点混乱,我仍在研究其中的某些部分,但对我有用。 You could try this. 你可以试试看。

<plugin>
     <groupId>org.jacoco</groupId>
     <artifactId>jacoco-maven-plugin</artifactId>
     <version>0.8.4</version>
            <executions>
                <execution>
                    <id>default-prepare-agent</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
                <execution>
                    <id>default-report</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                </execution>
                <execution>
                    <id>default-check</id>
                    <goals>
                        <goal>check</goal>
                    </goals>
                    <configuration>
                        <rules>
                            <rule>
                                <element>BUNDLE</element>
                                <limits>
                                    <limit>
                                        <counter>COMPLEXITY</counter>
                                        <value>COVEREDRATIO</value>
                                        <minimum>0.20</minimum>
                                    </limit>
                                </limits>
                            </rule>
                        </rules>
                    </configuration>
                </execution>
            </executions>
        </plugin>

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

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