首页 > 解决方案 > Maven 故障安全系统PropertyVariables

问题描述

systemPropertyVariablesmaven-failsafe-plugin. 在集成阶段运行集成测试时,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>

提前致谢。问候

标签: mavenintellij-ideamaven-failsafe-plugin

解决方案


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

<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-test, mvn verify,mvn deploy使用它们。
  • 任何命令都将使用includes.

推荐阅读