gpt4 book ai didi

java - 如何在maven中添加JaCoCo

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:47:03 25 4
gpt4 key购买 nike

我已经使用 JUnit 编写了一个单元测试用例,现在我想在我正在移动 3.2.1 的构建工具中添加 JaCoCo。我是 Maven 的新手。添加时,我不得不怀疑我要将它添加到依赖项还是插件中?两者都有,如下图

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.2-SNAPSHOT</version>
</plugin>

<dependency>
<groupId>org.codehaus.sonar.plugins</groupId>
<artifactId>sonar-jacoco-plugin</artifactId>
<version>3.2.1</version>
</dependency>

我希望将它附加到依赖项中,对于插件来说是否足够?

请任何机构澄清

最佳答案

JaCoCo Java Code Coverage LibraryJaCoCo 是一个免费的 Java 代码覆盖率库,由 EclEmma 团队根据多年使用和集成现有库的经验教训创建。 Example

<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<configuration>
<skip>false</skip>
<check/>
<rules>
<rule>
<element>CLASS</element>
<excludes>
<exclude>*Test</exclude>
</excludes>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.50</minimum>
</limit>
</limits>
</rule>
</rules>
</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>
<configuration>
<outputDirectory>${project.build.directory}/jacoco</outputDirectory>
</configuration>
</execution>
<execution>
<id>check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<check>
<instructionRatio>100</instructionRatio>
<branchRatio>95</branchRatio>
<lineRatio>90</lineRatio>
<methodRatio>90</methodRatio>
<classRatio>90</classRatio>
</check>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

GitHUb 存储库 JaCoCo

关于java - 如何在maven中添加JaCoCo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25483859/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com