如何解决Surefire“测试被跳过”和jacoco“由于缺少执行数据文件而跳过JaCoCo执行”?

问题描述 投票:0回答:1

我想生成 jacoco 报告,但不幸的是 Maven 没有运行测试并且没有生成报告。运行 mvn test 时,控制台显示以下内容 -

--- jacoco-maven-plugin:0.8.8:prepare-agent (prepare-agent) @ xx ---
[INFO] argLine set to -javaagent:C:\\xxx\\xx\\.m2\\repository\\org\\jacoco\\org.jacoco.agent\\0.8.8\\org.jacoco.agent-0.8.8-runtime.jar=destfile=C:\\xx\\xx\\git\\xx-xx\\target\\jacoco.exec
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ xx ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 16 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ xx ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 33 source files to C:\xx\xx\git\xx-xx\target\classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ xx ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 6 resources
[INFO] Copying 20 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ xx ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 16 source files to C:\xx\xx\git\xx-xx\target\test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:3.0.0-M5:test (default-test) @ xx ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- jacoco-maven-plugin:0.8.8:report (report) @ xx ---
[INFO] Skipping JaCoCo execution due to missing execution data file.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  11.570 s
[INFO] Finished at: 2023-08-22T15:42:57+02:00
[INFO] ------------------------------------------------------------------------

Process finished with exit code 0

我在 pom.xml 中做了很多调整,但仍然没有成功。我评论了一些依赖项并尝试执行相同的操作。我不确定这里到底出了什么问题。注释的依赖项已经尝试过。我的 pom.xml 看起来像 -

             <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>3.1.2</version>
            </plugin>
            <!--<plugin>
                <groupId>org.sonarsource.scanner.maven</groupId>
                <artifactId>sonar-maven-plugin</artifactId>
                <version>3.7.0.1746</version>
            </plugin>-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <!--<version>3.0.0-M5</version>-->
                <version>3.0.0-M5</version>
                <configuration>
                <skipTests>false</skipTests>
                    <includes>
                        <include>/**/*Test</include>
                       <!-- <include> **/*test/java/*</include> -->
                    </includes>
                </configuration>
                <executions>
                <execution>
                    <id>default-test</id>
                    <configuration>
                        <skip>false</skip>
                    </configuration>
                </execution>
                </executions>
                <!--<configuration>
                   <testFailureIgnore>false</testFailureIgnore>
                    <argLine>-Xmx1024M ${argLine}</argLine>
                    <forkedProcessExitTimeoutInSeconds>240</forkedProcessExitTimeoutInSeconds>
                </configuration>-->
            </plugin>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.8</version>
        <!--        <configuration>
                    <excludes>
                        <exclude>**/*test/java/*</exclude>
                        <exclude>**/*test/resources/*</exclude>
                    </excludes>
                </configuration>-->
                <executions>
                    <execution>
                        <id>prepare-agent</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>report</id>
                        <!-- <phase>prepare-package</phase>-->
                         <goals>
                             <goal>report</goal>
                         </goals>
                        <phase>test</phase>
                    </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.60</minimum>
                                         </limit>
                                     </limits>
                                 </rule>
                             </rules>
                         </configuration>
                    </execution>-->
                </executions>
            </plugin>
        </plugins>
        <sourceDirectory>src/main/java</sourceDirectory>
        <testSourceDirectory>src/test/java</testSourceDirectory>

stackoverflow 中提供的大多数解决方案都已经过尝试和测试,但到目前为止还没有成功。

java spring-boot maven junit5 jacoco
1个回答
0
投票

您可以尝试使用以下代码更新

pom.xml
中的现有插件,它在我的本地 Spring Boot 应用程序中使用 java 1.8 和高于 3.0 的 maven 版本运行良好。

jacoco 报告插件:

            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.6</version>
                <executions>
                    <execution>
                        <id>prepare-agent</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>report</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
© www.soinside.com 2019 - 2024. All rights reserved.