系统属性来自带有 Spock 测试的 maven 故障安全插件



我正在尝试让 maven 故障保护来执行我的集成测试,但是我在将服务器端口正确分配给系统属性时遇到了问题。

我的故障安全插件配置:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.21.0</version>
    <executions>
        <execution>
            <id>integration-tests</id>
            <goals>
                <goal>integration-test</goal>
                <goal>verify</goal>
            </goals>
            <configuration>
                <useSystemClassLoader>false</useSystemClassLoader>
                <systemPropertyVariables>
                    <test.server.port>${tomcat.http.port}</test.server.port>
                </systemPropertyVariables>
                <skipTests>${skip.integration.tests}</skipTests>
            </configuration>
        </execution>
    </executions>
</plugin>

我的斯波克测试配置:

def "verifies port is being set correctly"() {
    expect:
    System.getProperties().getProperty('test.server.port') != null
}

当我运行测试时,test.server.port不会出现在我的系统属性数组中。但是,如果我将其更改为asdf或任何非test.server.port的内容,它将出现在我的系统属性中。

修复是使用 Spring Boot 的随机端口进行环境初始化

@SpringBootTest(
        classes = OrderQueueApplication.class,
        webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT
)

最新更新