java - JaCoCo(离线仪器)在乐器 分析整个 pom.xml。但我只需要测试部分
问题描述
基本上我只需要 jacoco 对测试部分进行检测,但是对整个 pom.xml 进行检测,并且报告附带了所有内容(来自“oracle.jdbc.driver”、“com.mysql.jdbc”等的数据)
我已经尝试了几天几乎所有的东西。但到目前为止我还没有成功
请注意这里jacoco:instrument如何检测整个 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/classes
课程多于src
,那么如果没有相应的inclusions
/exclusions
他们也将被检测和报告。
请注意,排除课程instrumentation
不足以排除课程report
- 引用JaCoCo 常见问题解答:
报告生成器无法区分该类是从检测中排除还是未执行
因此,请确保您正确配置了instrument
和report
目标的执行。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>
推荐阅读
- wordpress - 从自定义页面调用时,Woocommerce 产品档案不显示任何内容
- kdb - 创建新目录 kdb+
- git - 您可以使用 Azure Devops Server repos 中的 ssh 进行 git clone 吗?
- javascript - node.js和python中相同问题解决方案的不同结果
- javascript - 在套件脚本 2.0 中加载保存的搜索时 search.run().getRange 出错
- html - Chrome浏览器计算错误的元素宽度
- c# - GMap.NET 我怎样才能做出准确的路由?
- powershell - PowerShell获取包含IP地址的行并将所有这些行保存在另一个文件中
- c# - .Net core 3.x Keyless Entity Types 避免创建表
- shopify - 将元字段暴露给 Storefront API 错误