我想生成junit的测试覆盖率报告。所以我使用 jacoco maven 插件:
这是我的 pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<compilerVersion>${java.version}</compilerVersion>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.8</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>jacoco-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>PACKAGE</element>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.50</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
但是当我运行这个时:
mvn clean verify
Run Code Online (Sandbox Code Playgroud)
我收到错误:
Results :
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- jacoco-maven-plugin:0.8.8:report (report) @ mymodule1 ---
[INFO] Loading execution data file /home/alexeij/dev/projects/JavaTestMavenBOM/mymodule1/target/jacoco.exec
[INFO] Analyzed bundle 'mymodule1' with 7 classes
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ mymodule1 ---
[INFO] Building jar: /home/alexeij/dev/projects/JavaTestMavenBOM/mymodule1/target/mymodule1-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- jacoco-maven-plugin:0.8.8:check (jacoco-check) @ mymodule1 ---
[INFO] Loading execution data file /home/alexeij/dev/projects/JavaTestMavenBOM/mymodule1/target/jacoco.exec
[INFO] Analyzed bundle 'mymodule1' with 7 classes
[WARNING] Rule violated for package com.gmail.alexei28.javatestmavenbom.module1.ngnms: lines covered ratio is 0.00, but expected minimum is 0.50
[WARNING] Rule violated for package com.gmail.alexei28.javatestmavenbom.module1: lines covered ratio is 0.00, but expected minimum is 0.50
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for testprojectbom 1.0-SNAPSHOT:
[INFO]
[INFO] testprojectbom ..................................... SUCCESS [ 0.090 s]
[INFO] mymodule1 .......................................... FAILURE [ 1.710 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.961 s
[INFO] Finished at: 2022-06-01T12:24:30+03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.jacoco:jacoco-maven-plugin:0.8.8:check (jacoco-check) on project mymodule1: Coverage checks have not been met. See log for details. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
Run Code Online (Sandbox Code Playgroud)
细节:
[ERROR] Failed to execute goal org.jacoco:jacoco-maven-plugin:0.8.5:check (jacoco-check) on project mymodule1: Coverage checks have not been met. See log for details. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.jacoco:jacoco-maven-plugin:0.8.5:check (jacoco-check) on project mymodule1: Coverage checks have not been met. See log for details.
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)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:972)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.plugin.MojoExecutionException: Coverage checks have not been met. See log for details.
at org.jacoco.maven.CheckMojo.executeCheck (CheckMojo.java:194)
at org.jacoco.maven.CheckMojo.executeMojo (CheckMojo.java:169)
at org.jacoco.maven.AbstractJacocoMojo.execute (AbstractJacocoMojo.java:46)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:972)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
[ERROR]
Run Code Online (Sandbox Code Playgroud)
您的输出是预期的。
\n报告在文件夹中生成target/site/jacoco。请参阅下面的 Maven 构建日志。
[INFO] --- jacoco-maven-plugin:0.8.8:report (report) @ mymodule1 ---\n[INFO] Loading execution data file /home/alexeij/dev/projects/JavaTestMavenBOM/mymodule1/target/jacoco.exec\n[INFO] Analyzed bundle \'mymodule1\' with 7 classes\nRun Code Online (Sandbox Code Playgroud)\n检查您的target/site/jacoco文件夹,它应该类似于以下内容:
[INFO] --- jacoco-maven-plugin:0.8.8:report (report) @ mymodule1 ---\n[INFO] Loading execution data file /home/alexeij/dev/projects/JavaTestMavenBOM/mymodule1/target/jacoco.exec\n[INFO] Analyzed bundle \'mymodule1\' with 7 classes\nRun Code Online (Sandbox Code Playgroud)\n您的构建配置如下:
\nprepare-agent目标initialize。report目标test。check目标verify。verify您的构建因未能符合配置而在阶段失败check。目标误差check如下:
\n\n\n
Coverage checks have not been met. See log for details。
以下是告诉您失败详细信息的日志。
\ntarget/site/jacoco/\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 index.html\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 io.sampadadubey.java.jacoco\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 index.html\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 index.source.html\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 JacocoDemoApplication.html\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 JacocoDemoApplication.java.html\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 jacoco.csv\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 jacoco-resources\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 branchfc.gif\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 branchnc.gif\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 branchpc.gif\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 bundle.gif\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 class.gif\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 down.gif\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 greenbar.gif\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 group.gif\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 method.gif\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 package.gif\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 prettify.css\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 prettify.js\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 redbar.gif\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 report.css\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 report.gif\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 session.gif\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 sort.gif\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 sort.js\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 source.gif\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 up.gif\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 jacoco-sessions.html\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 jacoco.xml\nRun Code Online (Sandbox Code Playgroud)\n为了使其更容易阅读。
\n[INFO] --- jacoco-maven-plugin:0.8.8:check (jacoco-check) @ mymodule1 ---\n[INFO] Loading execution data file /home/alexeij/dev/projects/JavaTestMavenBOM/mymodule1/target/jacoco.exec\n[INFO] Analyzed bundle \'mymodule1\' with 7 classes\n[WARNING] Rule violated for package com.gmail.alexei28.javatestmavenbom.module1.ngnms: lines covered ratio is 0.00, but expected minimum is 0.50\n[WARNING] Rule violated for package com.gmail.alexei28.javatestmavenbom.module1: lines covered ratio is 0.00, but expected minimum is 0.50\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
11381 次 |
| 最近记录: |