I am trying to get maven failsafe to execute my integration tests, however I am having a problem with the server port being correctly assigned to the system properties.
My failsafe plugin configuration:
<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>
My spock test configuration:
def "verifies port is being set correctly"() {
expect:
System.getProperties().getProperty('test.server.port') != null
}
When I run the test, test.server.port
does not appear in my system properties array. However, if I change it to asdf
or anything NOT test.server.port, it then appears in my system properties.
The fix was to use Spring Boot's random port for environment initialization
@SpringBootTest(
classes = OrderQueueApplication.class,
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.