【问题标题】:JACoCo/surefire-plugin does not find tests to runJACoCo/surefire-plugin 找不到要运行的测试
【发布时间】:2021-07-07 00:15:45
【问题描述】:

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

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

<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.*.**.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
[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 版本中得到认可,我们将不胜感激。谢谢

【问题讨论】:

    标签: java intellij-idea maven-2 jacoco


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2011-05-09
      • 2021-09-13
      • 2012-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-02
      • 2021-07-09
      • 2015-12-26
      相关资源
      最近更新 更多