Maven文档 - 查看代码测试覆盖率

173 阅读1分钟

执行方法

mvn clean verify jacoco:report -Dmaven.test.skip=false

(如果找不到mvn 先执行下 source ~/.bash_profile)

方法解释

The command you provided is a Maven command that performs the following tasks:

  1. mvn clean: This cleans the project by removing any previously generated build artifacts, such as the target directory.

  2. verify: This runs the project's verification tasks, which typically include running the unit and integration tests.

  3. jacoco:report: This generates a code coverage report using the JaCoCo code coverage tool. JaCoCo is a Java code coverage library that can be used to measure and report code coverage during the execution of tests.

  4. -Dmaven.test.skip=false: This ensures that the tests are not skipped during the build process, even if the maven.test.skip property is set to true elsewhere in the project.

The purpose of this command is to clean the project, run the verification tasks (including tests), and generate a code coverage report. The code coverage report can be useful for assessing the quality and completeness of the project's test suite.

关键步骤

<1> Cleaning the project 

<2> Running the verification tasks (including tests) 

<3> Generating a JaCoCo code coverage report 

覆盖率报告

The report is generated in the /path/to/my-project/target/site/jacoco/index.html file, which you can open in a web browser to view the code coverage results.