Maven 故障安全系统属性变量

Maven failsafe systemPropertyVariables

我为 maven-failsafe-plugin 定义了一些 systemPropertyVariables。 当集成测试在集成阶段 运行 时,systemPropertyVariables 被正确拾取。

当我 运行 通过我的 IDE (IntelliJ) 进行单个测试时,systemPropertyVariables 也会被拾取,但我不希望那样。

有没有办法在不使用 maven 配置文件的情况下防止这种情况发生?

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>3.0.0-M3</version>
                <configuration>
                    <includes>
                        <include>**/*End2EndTest.java</include>
                    </includes>
                    <systemPropertyVariables>
                        <tomcat.host>host</tomcat.host>
                        <tomcat.port>8080</tomcat.port>
                        <tomcat.context>/</tomcat.context>
                        <tests.browser.name>chrome</tests.browser.name>
                        <tests.selenium.grid.address>http://localhost:4444/wd/hub/</tests.selenium.grid.address>
                        <spring.profiles.active>build</spring.profiles.active>
                    </systemPropertyVariables>
                </configuration>
            </plugin>
        </plugins>
     </build>

提前致谢。 问候

configuration 元素处于 plugin 级别,因此它将应用于所有构建。要限制它,请创建一个执行并将配置移入其中。

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>3.0.0-M3</version>
    <configuration>
        <!-- this configuration applies to all builds
             using this plugin, whether by specific
             goal, or phase.  -->
        <includes>
            <include>**/*End2EndTest.java</include>
        </includes>
    </configuration>
    <executions>
        <execution>
            <!-- this configuration only is used if
                 the integration-test phase, or later
                 phase, is executed -->
            <id>integration-test</id>
            <phase>integration-test</phase>
            <goals>
                <goal>integration-test</goal>
            </goals>
            <configuration>
                <systemPropertyVariables>
                    <tomcat.host>host</tomcat.host>
                    <tomcat.port>8080</tomcat.port>
                    <tomcat.context>/</tomcat.context>
                    <tests.browser.name>chrome</tests.browser.name>
                    <tests.selenium.grid.address>http://localhost:4444/wd/hub/</tests.selenium.grid.address>
                    <spring.profiles.active>build</spring.profiles.active>
                </systemPropertyVariables>
            </configuration>
        </execution>
    </executions>    
</plugin>

有了这个:

  • mvn failsafe:integration-test 不会获取系统属性。
  • mvn integration-testmvn verifymvn deploy使用它们。
  • 任何命令都将使用 includes