我有一个Maven多模块项目。
root:
moduleA/ # no unit tests
moduleB/ # no unit tests
moduleC/ # no unit tests
tests/ # All unit tests, since depends on modules A, B and C
Run Code Online (Sandbox Code Playgroud)
所有测试都在称为tests /的单个模块中,所有代码都在单独的模块中。
有没有办法获得代码覆盖率?
我们的jacoco.exec文件有几个不同的错误,请参阅下面的错误类型.
能否帮助我们解决这个问题,我们至少有25%的构建失败Jacoco.
错误类型1:
09:18:17 [INFO] ------------------------------------------------------------------------
09:18:17 [INFO] BUILD FAILURE
09:18:17 [INFO] ------------------------------------------------------------------------
09:18:17 [INFO] Total time: 02:02 min
09:18:17 [INFO] Finished at: 2015-12-22T09:18:17+01:00
09:18:17 [INFO] Final Memory: 148M/2933M
09:18:17 [INFO] ------------------------------------------------------------------------
09:18:17 [ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.7.1:sonar (default-cli) on project athena: Unable to read /repo/jenkins/production/workspace/CSW_All_Build_PreMerge-gate/support-functions/Common/target/jacoco.exec: malformed input around byte 2 -> [Help 1]
09:18:17 [ERROR]
09:18:17 [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
09:18:17 [ERROR] …Run Code Online (Sandbox Code Playgroud) 在我的基于环境变量的项目中,运行了不同的集成测试集。例如
mvn test -Dconfig=a
mvn test -Dconfig=b
Run Code Online (Sandbox Code Playgroud)
同时运行这两条线可提供完整的测试范围。
现在的问题是,每次运行都会在目标文件夹中创建一个jacoco.exec文件,但是第二次运行将通过删除目标文件夹来覆盖第一个运行。
我想使用jacoco merge合并exec文件,但是我不确定该怎么做。
我可以将输出目录更改为目标和合并以外的其他位置,但是合并后如何维护版本或必须添加一行以删除文件夹。
任何帮助,将不胜感激
我有一个共享的 groovy 库,它为 Jenkins 管道提供了一些步骤(在 vars 文件夹中)。对于这些步骤,我进行了 groovy 单元测试,并希望使用它们计算代码覆盖率。我已经成功设置了 jacoco 并获得了我的对象的覆盖结果(在 src 文件夹中)。但是,jacoco 不会计算步骤的覆盖率,因为它们不在类路径上。
知道如何获得此步骤的覆盖范围吗?任何有这方面经验的人?
groovy jenkins jacoco jacoco-maven-plugin jenkins-shared-libraries
我一直在尝试从生成的覆盖率报告中删除某些文件。我尝试了以下事情:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.1</version>
<executions>
<execution>
<id>report-aggregate</id>
<phase>verify</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
<configuration>
<excludes>
<exclude>**/com/abc/def/**</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule >
<element>BUNDLE</element>
<limits>
<limit >
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.50</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
修改后的代码:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<configuration>
<excludes>
<exclude>**/com/abc/def/**</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>report-aggregate</id>
<phase>verify</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
</execution>
<execution>
<id>check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule >
<element>BUNDLE</element>
<limits>
<limit >
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.50</minimum>
</limit>
</limits>
</rule>
</rules> …Run Code Online (Sandbox Code Playgroud) configuration code-coverage pom.xml jacoco jacoco-maven-plugin
我的项目是使用 Maven 构建的。我使用“Jacoco”插件来执行质量检查。
对于一个项目,我想在线检查测试覆盖率。我只想检查仅 3 个包裹的线路覆盖率。如何指定此检查?
我尝试“包括”一些软件包,但这不起作用。我还尝试包含根包级别并排除许多其他包。也不工作。
我如何检查包裹 A、B 和 C?请参阅下面的示例:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<executions>
...
<execution>
<id>jacoco-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>PACKAGE</element>
<includes>
<include>nl.abc.xyz.package-a.**</include>
<include>nl.abc.xyz.package-b.**</include>
<include>nl.abc.xyz.package-c.**</include>
</includes>
...
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.30</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud) 基本上我只需要 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
Run Code Online (Sandbox Code Playgroud)
我的测试运行
[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
Run Code Online (Sandbox Code Playgroud)
这是我的 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 --- …Run Code Online (Sandbox Code Playgroud) 错误:
[ERROR] Failed to execute goal org.jacoco:jacoco-maven-plugin:0.8.5:report-aggregate (report-aggregate) on project distribution: Unable to parse configuration of mojo org.jacoco:jacoco-maven-plugin:0.8.5:report-aggregate for parameter dataFileIncludes: Cannot assign configuration entry 'dataFileIncludes' with value '**/jacoco-unit.exec' of type java.lang.String to property of type java.util.List -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
Run Code Online (Sandbox Code Playgroud)
pom.xml
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.2</version>
<executions>
<execution>
<id>report-aggregate</id>
<phase>prepare-package</phase>
<goals>
<goal>report-aggregate</goal> …Run Code Online (Sandbox Code Playgroud) 所以我使用 JaCoco maven 插件自动生成代码覆盖率报告,以便我可以将它们发送到 codecov 以显示在 GitHub 上。突然间,我从 JaCoco 那里得到了一个构建失败,说“未知块类型”。这不是昨天发生的,所以我不知道为什么现在会发生。这是我的 pom.xml 的相关部分
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
如何解决此问题以正确生成覆盖率报告?
-X 跟踪
[DEBUG] Configuring mojo org.jacoco:jacoco-maven-plugin:0.8.5:report from plugin realm ClassRealm[plugin>org.jacoco:jacoco-maven-plugin:0.8.5, parent: jdk.internal.loader.ClassLoaders$AppClassLoader@55054057]
[DEBUG] Setting property: classpath.resource.loader.class => 'org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader'.
[DEBUG] Setting property: site.resource.loader.class => 'org.codehaus.plexus.velocity.SiteResourceLoader'.
[DEBUG] Setting property: velocimacro.messages.on => 'false'.
[DEBUG] Setting property: runtime.log.invalid.references => 'false'.
[DEBUG] Setting property: resource.loader => 'classpath,site'.
[DEBUG] Setting property: velocimacro.permissions.allow.inline.to.replace.global => 'true'. …Run Code Online (Sandbox Code Playgroud) 这是我在运行 mvn jacoco:check for a maven application 时遇到的错误。因此,不会生成报告。
[ERROR] Failed to execute goal org.jacoco:jacoco-maven-plugin:0.8.3:check (default-cli) on project
Netflix: The parameters 'rules' for goal org.jacoco:jacoco-maven-plugin:0.8.3:check are missing or invalid -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.jacoco:jacoco-maven-plugin:0.8.3:check (default-cli) on project Netflix: The parameters 'rules' for goal org.jacoco:jacoco-maven-plugin:0.8.3:check are missing or invalid
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
Run Code Online (Sandbox Code Playgroud)
这是我在 pom.xml 中的 jacoco 插件。我觉得规则没问题。我想知道缺少什么...
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.2</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<phase>test</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<!-- Sets the …Run Code Online (Sandbox Code Playgroud)