Pav*_*vel 5 java maven jacoco jacoco-maven-plugin
Jacoco 插件丢失了 JUnit 测试,报告始终为 0%,但测试存在。我认为问题是我的pom.xml。帮我找出错误。
也许它与插件冲突checkstyle?
部分 Jacoco 设置:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.9.1</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>2.22.2</version>
<configuration>
<reportFormat>plain</reportFormat>
<includes>
<include>**/*Test*.java</include>
<include>**/*IT*.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>jacoco-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>PACKAGE</element>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.0</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.1.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${checkstyle.version}</version>
<configuration>
<configLocation>checkstyle.xml</configLocation>
</configuration>
<reportSets>
<reportSet>
<reports>
<report>checkstyle</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
Run Code Online (Sandbox Code Playgroud)
没有执行测试,因此没有覆盖范围。
在构建日志中你有
[INFO] Tests are skipped.
Run Code Online (Sandbox Code Playgroud)
这可能是由于-DskipTests您的.github/workflows/build.yml
run: mvn -B clean package -DskipTests
Run Code Online (Sandbox Code Playgroud)
执行mvn test产品
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ bridge ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
Run Code Online (Sandbox Code Playgroud)
因为您有junit-jupiter依赖项,但没有junit-vintage-engine(请参阅 的输出mvn dependency:tree),而您的测试是使用 JUnit 4 编写的。
删除排除后如下junit-vintage-engine
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
+ <!--
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
+ -->
Run Code Online (Sandbox Code Playgroud)
执行mvn test产品
[INFO] Tests run: 47, Failures: 0, Errors: 0, Skipped: 0
Run Code Online (Sandbox Code Playgroud)
以及以下报告
| 归档时间: |
|
| 查看次数: |
10063 次 |
| 最近记录: |