gpt4 book ai didi

java - instrument 中的 JaCoCo(离线检测)分析整个 pom.xml。但我只需要测试部分

转载 作者:行者123 更新时间:2023-12-01 12:00:59 27 4
gpt4 key购买 nike

基本上我只需要 jacoco 检测测试部分,但是检测整个 pom.xml,并且报告随附了所有内容(来自“oracle.jdbc.driver”、“com.mysql.jdbc”...等的数据)

我已经尝试了几天几乎所有的东西。但到目前为止我还没有成功

注意这里是如何 jacoco:仪器检测整个 pom.xml

[INFO] --- jacoco-maven-plugin:0.8.4:instrument (default-instrument) @ myApp ---
...
[DEBUG] (f) project = MavenProject: com.firstPackage.tdz:myApp:X.1.0 @ C:\rootFolder\my_app\server\MyApp\pom.xml

我的测试运行
[INFO] --- maven-compiler-plugin:3.5.1:testCompile (default-testCompile) @ myApp ---
[DEBUG] Source directories: [C:\rootFolder\my_app\server\myApp\tests\src]
[DEBUG] Classpath: [C:\devel\my_app\server\myApp\target\test-classes

这是我的 Maven 流程:
[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) @ myApp ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 3582 source files to c:\rootFolder\my_app\server\myApp\target\classes
...
[INFO] --- aspectj-maven-plugin:1.3:compile (default) @ myApp ---
...
[INFO] --- jacoco-maven-plugin:0.8.4:instrument (default-instrument) @ myApp ---
...
[INFO] --- maven-compiler-plugin:3.5.1:testCompile (default-testCompile) @ myApp ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 326 source files to c:\rootFolder\my_app\server\myApp\target\test-classes
...
[INFO] --- aspectj-maven-plugin:1.3:test-compile (default) @ myApp ---
...
[INFO] --- maven-surefire-plugin:2.15:test (default-test) @ myApp ---

... finally

[INFO] --- jacoco-maven-plugin:0.8.4:restore-instrumented-classes (default-restore-instrumented-classes) @ myApp ---
...
[INFO] --- jacoco-maven-plugin:0.8.4:report (default-report) @ myApp ---
[INFO] Loading execution data file c:\devel\my_app\server\MyApp\target\jacoco.exec
[INFO] Analyzed bundle 'myApp' with 5562 classes

在“Jacoco default-instrument”中用于仅运行测试部分的任何真实示例都会很棒。这可能吗?
<execution>
<id>default-instrument</id>
<goals>
<goal>instrument</goal>
</goals>
<configuration>
<!-- any real example here? Notice maven's behavior above -->
</configuration>
</execution>

最佳答案

两者 jacoco:instrument jacoco:report target/classes 一起操作,因为这是执行并测量其覆盖率的类。

如果您放置在 target/classessrc 中的类(class)更多, 那么没有对应的 inclusions/exclusions它们也将被检测和报告。

请注意从 instrumentation 中排除类不足以从 report 中排除类- 引用 JaCoCo FAQ :

report generator cannot distinguish whether the class was excluded from instrumentation or not executed



所以请确保您正确配置了 的执行两者 instrumentreport目标 . Maven 允许多种不同的方式来配置不同目标的不同执行,这里只是示例之一:

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<execution>
<goals>
<goal>instrument</goal>
<goal>report</goal>
</goals>
<configuration>
<!-- this configuration affects this "execution" of "instrument" and "report" goals -->
<excludes>*</excludes>
</configuration>
</execution>

关于java - <goal>instrument</goal> 中的 JaCoCo(离线检测)分析整个 pom.xml。但我只需要测试部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58189496/

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