【问题标题】:How to generate report for integration tests using mvn site command如何使用 mvn site 命令生成集成测试报告
【发布时间】:2017-08-20 10:00:53
【问题描述】:

我有一些单元测试(src/test 文件夹中的 *Test.java 类,由 Surefire 插件执行)和其他一些集成测试(src/it 文件夹中的 *IT.java 类,由 Failsafe 插件执行):.xml当我运行
mvn install 时,会在文件夹 target/surfire-reports 和 target/failsafe-reports 中正确生成 .txt 报告。

此外,我希望有 html 报告:我认为最好的解决方案应该是使用 mvn site,以便也有 CSS 文件。
但是,现在只执行单元测试,因此只生成目标/surfire-reports,显然生成的唯一 html 文档是关于单元测试的。

POM sn-p 下面:

<build>
...
   <plugin>
      <artifactId>maven-surefire-plugin</artifactId>
      ...
   </plugin>
   <plugin>
      <artifactId>maven-failsafe-plugin</artifactId>
      ...
      <goal>integration-test</goal>
      <goal>verify</goal>
      ...
   </plugin>
   <plugin> 
      // definition of build helper maven plugin for the registration 
      // of the src/it folder
   </plugin>
...
</build>

<reporting>
  <plugins>
     <plugin>
         <groupId>org.maven.maven.plugins</groupId>
         <artifactId>maven-surefire-report-plugin</artifactId>
         <version>2.19.1</version>
     </plugin>
   </plugins>
</reporting>

显然,mvn site 没有执行集成测试目标,但我该如何解决?

PS:一个愚蠢的解决方案是在 mvn install 之后运行 mvn site(没有清理),但我想要更聪明的东西。

【问题讨论】:

    标签: maven unit-testing integration-testing maven-plugin maven-surefire-plugin


    【解决方案1】:

    有三个内置的构建生命周期:默认、干净和站点。 默认生命周期处理您的项目部署,干净 生命周期处理项目清理,而站点生命周期处理 创建项目的站点文档。

    • default 生命周期中,您会找到“verify”步骤,这是运行集成测试的步骤
    • 站点生命周期中,您将执行站点。

    所以命令应该是:

    mvn clean verify site
    

    (除非有特殊要求,否则请始终清理您的工作区)

    Maven Build Lifecycle Basics

    【讨论】:

      【解决方案2】:

      在你的 pom 中使用 JaCoCo 插件并运行 mvn clean verify 命令。它是开源的,很容易实现。

      <plugin>
          <groupId>org.jacoco</groupId>
          <artifactId>jacoco-maven-plugin</artifactId>
          <version>0.7.7.201606060606</version>
          <executions>
              <execution>
                  <goals>
                      <goal>prepare-agent</goal>
                  </goals>
              </execution>
              <execution>
                  <id>report</id>
                  <phase>prepare-package</phase>
                  <goals>
                      <goal>report</goal>
                  </goals>
              </execution>
          </executions>
      </plugin>
      

      将此添加到您的 pom.xml 中。它将在target/site/jacoco 目录中生成报告。如果你想将它与 SonarQube 集成,很容易设置添加一些参数并运行命令mvn sonar:sonar。更多详情:https://medium.com/backend-habit/generate-codecoverage-report-with-jacoco-and-sonarqube-ed15c4045885

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-11-16
        • 2017-05-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-08-21
        • 2014-09-26
        • 2021-11-08
        相关资源
        最近更新 更多