【问题标题】:Maven - run integration and unit testsMaven - 运行集成和单元测试
【发布时间】:2016-08-16 23:43:39
【问题描述】:

我在 Maven 中定义了 2 组测试 - 集成测试和测试。

如果我运行 maven test - 我的测试运行

如果我运行maven integration-test - 两者都运行

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.4.3</version>
    <executions>
      <execution>
        <id>default-test</id>
        <configuration>
          <forkMode>always</forkMode>
          <excludes>
            <exclude>**/TC_Integration*</exclude>
          </excludes>
          <includes>
            <include>**/TC_*</include>
          </includes>
        </configuration>
      </execution>
      <execution>
        <id>integration-test</id>
        <phase>integration-test</phase>
        <goals>
          <goal>test</goal>
        </goals>
        <configuration>
          <excludes>
            <exclude>**/TC_Unit*</exclude>
          </excludes>
          <includes>
            <include>**/TC_*</include>
          </includes>
        </configuration>
      </execution>
    </executions>
  </plugin>
  <plugin>

让两者始终运行的最佳方法是什么?我主要希望maven install 两者都运行,但事实并非如此。

【问题讨论】:

  • mvn verify 呢?
  • 首先使用 maven-failsafe-plugin 正如已经建议的那样,您应该遵循命名约定,这让生活更轻松...单元测试:*Test.java* 集成测试*IT.java...和使用@chrylis 已经提到的使用mvn verify否则post-integration-test 阶段将不会被执行,这有时需要集成测试来关闭或清理等。
  • 我无法更改测试名称。
  • 您能否阐明当前和预期的行为?我将你的代码复制到我的项目中,当我调用 mvn install 时,默认测试和集成测试都会启动
  • 我认为你是对的,实际上,我认为如果测试失败,它不会运行集成测试。

标签: java maven unit-testing


【解决方案1】:

不要尝试将surefire配置为同时运行单元测试和集成测试,而是将surefire配置为仅运行单元测试并使用故障安全插件运行集成测试。

https://maven.apache.org/surefire/maven-failsafe-plugin/

【讨论】:

    猜你喜欢
    • 2012-05-05
    • 2015-07-19
    • 2016-01-23
    • 2013-03-18
    • 2020-02-21
    • 2017-09-14
    • 2023-01-09
    • 2013-10-17
    • 1970-01-01
    相关资源
    最近更新 更多