maven - 如何使用 mvn site 命令生成集成测试报告

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

我有一些单元测试(src/test 文件夹中的 *Test.java 类,由 Surefire 插件执行)和其他一些集成测试(src/it 文件夹中的 *IT.java 类,由 Failsafe 插件执行):.xml 和 .txt当我运行 mvn install 时,报告会在文件夹 target/surfire-reports 和 target/failsafe-reports 中正确生成.
此外,我想要 html 报告:我认为最好的解决方案应该是使用 mvn site , 以便也有 CSS 文件。
然而,现在只执行单元测试,所以只生成目标/surfire-reports,显然生成的唯一 html 文档是关于单元测试的。
下面的 POM 片段:

<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(没有清理),但我想要更聪明的东西。

最佳答案

There are three built-in build lifecycles: default, clean and site. The default lifecycle handles your project deployment, the clean lifecycle handles project cleaning, while the site lifecycle handles the creation of your project's site documentation.


  • 默认 在生命周期中,您会发现“ 验证”步骤,该步骤将运行您的集成测试
  • 网站生命周期,您将拥有您的网站执行。

  • 所以命令应该是:
    mvn clean verify site
    
    (除非有特殊要求,否则请始终清洁您的工作空间)
    Maven Build Lifecycle Basics

    关于maven - 如何使用 mvn site 命令生成集成测试报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43050754/

    相关文章:

    java - maven:如何添加编译阶段后生成的资源

    maven - 构建 hadoop 1.0.1 时出错 - 缺少 pom.xml

    selenium - 使用 Selenium 的 CSS 模块?

    AngularJs 单元测试 - 检查 "Init"函数是否被调用

    angular - 如何在 karma 测试台中包含 Angular Material 库

    c# - .NET 核心测试 - 使用 FakeItEasy 模拟 IHttpContextAccessor

    java - 在 Play 框架中测试 Controller

    java - 如何在 Java 中使用 Ruby 和 Maven?

    maven - 一个 Maven 主文件夹可以有 2 个 settings.xml 吗?

    unit-testing - Visual Studio 2010 单元测试窗口和一般运行测试