Just so others who have configured their apps like mine benefit from what I went through...
None of the above solutions worked for me because I have a ./config directory just under my project base with 2 files:
application.properties
application-dev.properties
In application.properties I have:
spring.profiles.active = dev # set my default profile to 'dev'
In application-dev.properties I have:
server_host = localhost
server_port = 8080
This is so when I run my fat jar from the CLI the *.properties files will be read from the ./config dir and all is good.
Well, it turns out that these properties files completely override the webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT setting in @SpringBootTest in my Spock specs. No matter what I tried, even with webEnvironment set to RANDOM_PORT Spring would always startup the embedded Tomcat container on port 8080 (or whatever value I'd set in my ./config/*.properties files).
The ONLY way I was able to overcome this was by adding an explicit properties = "server_port=0" to the @SpringBootTest annotation in my Spock integration specs:
@SpringBootTest (webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = "server_port=0")
Then, and only then did Spring finally start to spin up Tomcat on a random port. IMHO this is a Spring testing framework bug, but I'm sure they'll have their own opinion on this.
Hope this helped someone.