我在maven中的jacoco插件有问题。虽然我在测试文件中有一些测试行,但是我的覆盖率是0.0。我不知道该怎么做。
我尝试从我的朋友pom中更改pom.xml,但这还是行不通的
这是制作maven.install的输出:
--- jacoco-maven-plugin:0.8.3:check (default-check) @ Sudoku ---
Loading execution data file D:\xd\inf\4 semestr\Programowanie Komponentowe\prokom_2019_lch_sr_12_01\target\jacoco.exec
Analyzed bundle 'Sudoku' with 8 classes
Rule violated for bundle Sudoku: complexity covered ratio is 0.000000, but expected minimum is 0.600000
这是我的pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.progkomp.Sudoku</groupId>
<artifactId>Sudoku</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>sudoku</name>
<url>http://maven.apache.org</url>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.0.0</version>
<reportSets>
<reportSet>
<reports>
<report>checkstyle</report>
</reports>
</reportSet>
</reportSets>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<reportSets>
<reportSet>
<reports>
<report>report</report>
</reports>
</reportSet>
</reportSets>
<version>0.8.3</version>
</plugin>
</plugins>
</reporting>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<configLocation>checkstyle.xml</configLocation>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<linkXRef>false</linkXRef>
</configuration>
<executions>
<execution>
<id>checkstyle</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.3</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>default-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>BUNDLE</element>
<limits>
<limit>
<counter>COMPLEXITY</counter>
<value>COVEREDRATIO</value>
<minimum>0.600000</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
在测试文件中,我大约有100行带有很多断言,因此问题仅出在插件上。
答案 0 :(得分:0)
在测试文件中,我大约有100行带有很多断言,因此问题仅出在插件上。
问题显然不是“仅使用插件”,pom.xml
不足以证明您的问题,因为添加了
src/main/java/Example.java
class Example {
}
和src/main/java/ExampleTest.java
public class ExampleTest {
@org.junit.Test
public void test() {
new Example();
}
}
和checkstyle.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
</module>
具有完全相同的pom.xml
执行mvn clean install
效果很好:
...
[INFO] --- jacoco-maven-plugin:0.8.3:check (default-check) @ Sudoku ---
[INFO] Loading execution data file /private/tmp/j/target/jacoco.exec
[INFO] Analyzed bundle 'Sudoku' with 1 classes
[INFO] All coverage checks have been met.
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.071 s
[INFO] Finished at: 2019-04-25T15:45:10+02:00
[INFO] ------------------------------------------------------------------------
因此,请阅读https://stackoverflow.com/help/mcve并提供完整的可验证示例,其中包含重现问题所需的所有部分。
答案 1 :(得分:0)
我得到了 0.0 的覆盖率,因为我所有的测试类都缺少公共范围,(默认情况下它们是私有的)