scala 我的Jacoco报告显示代码覆盖率非常低

elcex8rz  于 5个月前  发布在  Scala
关注(0)|答案(1)|浏览(58)

我想知道Scala的一些单元测试和Java的源代码(测试和代码在不同的包中)的代码覆盖率是多少,当我运行Jacoco报告时,它显示只有4%的代码覆盖率。
当我查看报告时,它显示了我为许多文件创建测试的0%。我怀疑单元测试没有被包含在报告中,可能是因为所有的测试类文件都在target/test-classes目录中。我尝试包含includeTests标记,但没有任何效果。
下面是插件在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>

字符串
现在我已经注解掉了include标签,因为如果我包含它,测试编译为0个类。否则我怎么能包含target/test-classes目录?
很抱歉,如果这是一个简单的修复,我很新的单元测试和Jacoco。谢谢!

cdmah0mi

cdmah0mi1#

这是我的个人设置。它有点乱,我仍然在工作的一些部分,但它为我工作。你可以试试这个。

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

字符串

相关问题