微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

JACoCo/surefire-plugin 找不到要运行的测试

如何解决JACoCo/surefire-plugin 找不到要运行的测试

我所有的测试都位于 src/test/java/... ,其中 java 标记为测试源文件夹。它们也都被命名为 ***Test 所以 Surefire 插件应该可以找到它们。

但是我的 Maven 验证失败了,因为我的所有测试覆盖率都为 0%。我有 20 个测试,它们应该涵盖我所有的非排除类,当我在 IntelliJ 中运行它们时,它们都通过了。当我运行 maven test 或 maven verify 我的测试没有运行时。我不知道为什么。

<plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.6</version>
                <executions>
                    <execution>
                        <id>default-prepare-agent</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>default-report</id>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>jacoco-check</id>
                        <goals>
                            <goal>check</goal>
                        </goals>
                        <configuration>
                            <excludes>
                                ...
                            </excludes>
                            <rules>
                                <rule>
                                    <element>CLASS</element>
                                    <limits>
                                        <limit>
                                            <counter>LINE</counter>
                                            <value>COVEREdratIO</value>
                                            <minimum>80%</minimum>
                                        </limit>
                                        <limit>
                                            <counter>BRANCH</counter>
                                            <value>COVEREdratIO</value>
                                            <minimum>80%</minimum>
                                        </limit>
                                    </limits>
                                </rule>
                            </rules>
                        </configuration>
                    </execution>
                    <execution>
                        <id>report</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M5</version>
            </plugin>
----------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- jacoco-maven-plugin:0.8.6:prepare-agent (default-prepare-agent) @ *-*-service ---
[INFO] surefireArgLine set to "-javaagent:C:\\Users\\*\\.m2\\repository\\org\\jacoco\\org.jacoco.agent\\0.8.6\\org.jacoco.agent-0.8.6-runtime.jar=destfile=C:\\Users\\*\\OneDrive\\Documents\\IntelliJ Projects\\*-*-service\\*-*-service\\target\\jacoco.exec,append=true"
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ *-*-service ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] copying 1 resource
[INFO] copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ *-*-service ---
[INFO] nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) @ *-*-service ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] skip non existing resourceDirectory C:\Users\*\OneDrive\Documents\IntelliJ Projects\*-*-service\*-*-service\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ *-*-service ---
[INFO] nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:3.0.0-M5:test (default-test) @ *-*-service ---
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[ERROR] Java HotSpot(TM) 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 0,Failures: 0,Errors: 0,Skipped: 0
[INFO] 
[INFO] 
[INFO] --- jacoco-maven-plugin:0.8.6:report (report) @ *-*-service ---
[INFO] Loading execution data file C:\Users\*\OneDrive\Documents\IntelliJ Projects\*-*-service\*-*-service\target\jacoco.exec
[INFO] Analyzed bundle '*-*-service' with 19 classes
[INFO] 
[INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) @ *-*-service ---
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.4.4:repackage (repackage) @ *-*-service ---
[INFO] Replacing main artifact with repackaged archive
[INFO] 
[INFO] --- jacoco-maven-plugin:0.8.6:report (default-report) @ *-*-service ---
[INFO] Loading execution data file C:\Users\*\OneDrive\Documents\IntelliJ Projects\*-*-service\*-*-service\target\jacoco.exec
[INFO] Analyzed bundle '*-*-service' with 19 classes
[INFO] 
[INFO] --- jacoco-maven-plugin:0.8.6:check (jacoco-check) @ *-*-service ---
[INFO] Loading execution data file C:\Users\*\OneDrive\Documents\IntelliJ Projects\*-*-service\*-*-service\target\jacoco.exec
[INFO] Analyzed bundle '*-*-service' with 6 classes
[WARNING] Rule violated for class com.*.**.mapper.*Mapper: lines covered ratio is 0.00,but expected minimum is 0.80
[WARNING] Rule violated for class com.*.**.mapper.*Mapper: branches covered ratio is 0.00,but expected minimum is 0.80
[WARNING] Rule violated for class com.*.**.mapper.*Mapper: lines covered ratio is 0.00,but expected minimum is 0.80
[WARNING] Rule violated for class com.*.**.controller.*Controller: lines covered ratio is 0.00,but expected minimum is 0.80
[WARNING] Rule violated for class com.*.**.service.*Service: lines covered ratio is 0.00,but expected minimum is 0.80
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  5.388 s
[INFO] Finished at: 2021-04-11T19:48:54+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.jacoco:jacoco-maven-plugin:0.8.6:check (jacoco-check) on project *-*-service: Coverage checks have not been met. See log for details. -> [Help 1]

我使用的是 IntelliJ-IDEA 终极版 2021.1(最新发布日期)

在完整的 Maven 构建中让我的测试得到认可的任何帮助将不胜感激。谢谢

解决方法

请阅读日志,并检查 [ERROR]。 您使用的是 JDK 13,并且某些 POM 在配置参数 argLine 中添加了 -Xverify:none-noverify

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。