代码之家  ›  专栏  ›  技术社区  ›  Piotr Pradzynski

当特定的弹簧外形激活时,如何防止运行测试?

  •  0
  • Piotr Pradzynski  · 技术社区  · 7 年前

    spring.profiles.active=prod ). 我希望在全局范围内(也许使用一些Maven插件)而不是单独在每个测试中执行。

    2 回复  |  直到 7 年前
        1
  •  1
  •   Shahzeb Khan    7 年前
    <profiles>
        <profile>
            <id>prod</id>
            <properties>
                <maven.test.skip>true</maven.test.skip>
            </properties>
        </profile>
    </profiles>
    
        2
  •  0
  •   Planck Constant    7 年前

    你可以用 @IfProfileValue https://docs.spring.io/spring/docs/current/spring-framework-reference/testing.html#integration-testing

    编辑: 另一种解决方案是排除Surefire插件中的所有(或选定的测试)测试:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
            <excludes>
             <exclude>${exclude.tests}</exclude>
            </excludes>
          </configuration>
    </plugin>
    ...
    <profile>
      <id>prod</id>
      <properties>
        <exclude.tests>**/*.*</exclude.tests>
      </properties>
    </profile>
    

    当你跑的时候 mvn clean test -Pprod 将跳过所有测试