目标仪器/目标中的JaCoCo(离线仪表).分析整个pom.xml.但是我只需要测试部分 [英] JaCoCo (Offline Instrumentation) in <goal>instrument</goal> analyzes the entire pom.xml. But I need only the tests part
问题描述
基本上,我只需要jacoco来测试测试部分,但是会显示整个pom.xml,并且报告包含所有内容(来自"oracle.jdbc.driver","com.mysql.jdbc"等的数据).
Basically I need jacoco only instrument the tests part, but is instrumententing the entire pom.xml, and the report came with everything (Data from "oracle.jdbc.driver", "com.mysql.jdbc"… etc.)
我已经尝试了几乎所有内容的几天.但是到目前为止我还没有成功
I've been trying for a couple of days with almost everything. But I have not succeeded so far
请注意此处 jacoco:instrument 如何检测整个pom.xml
Notice here how jacoco:instrument instrument the entire 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流程:
This is my maven flow:
[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"中都是不错的.有可能吗?
Any real example here would be great In "Jacoco default-instrument" for run only tests part. It is that possible?
<execution>
<id>default-instrument</id>
<goals>
<goal>instrument</goal>
</goals>
<configuration>
<!-- any real example here? Notice maven's behavior above -->
</configuration>
</execution>
推荐答案
jacoco:report
使用target/classes
进行操作,因为这是已执行的类,并且其覆盖范围已测量.
Both jacoco:instrument
and jacoco:report
operate with target/classes
, because this is the classes that are executed and whose coverage is measured.
如果与src
相比,在target/classes
中放置的类更多,那么如果没有相应的inclusions
/exclusions
,它们也将被检测和报告.
If you place in target/classes
more classes than in src
, then without corresponding inclusions
/ exclusions
they will also be instrumented and reported.
请注意,从instrumentation
中排除类不足以从report
中排除类-引用 JaCoCo常见问题解答:
Please note that exclusion of classes from instrumentation
is not enough to exclude classes from report
- quoting JaCoCo FAQ:
报告生成器无法区分该类是从检测中排除还是未执行
report generator cannot distinguish whether the class was excluded from instrumentation or not executed
因此,请确保已正确配置 instrument
和report
目标的执行. Maven允许采用多种不同的方式来配置不同目标的不同执行,这只是示例之一:
So please make sure that you properly configured execution of both instrument
and report
goals. Maven allows many different ways to configure different executions of different goals, here is just one of examples:
<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>
这篇关于目标仪器/目标中的JaCoCo(离线仪表).分析整个pom.xml.但是我只需要测试部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!