I have a pull request to bump Spring Boot from 2.7.6 to 3.0.0.
It fails with a compilation error on: import org.springframework.boot.web.server.LocalServerPort
If I try to resolve it by an import suggested by IDE (import org.springframework.boot.test.web.server.LocalServerPort), the port field is still null when tests are run.
Here's the test that fails:
package com.github.artamonovkirill
import com.tomtom.http.HttpClient
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.web.server.LocalServerPort
import spock.lang.Specification
import static com.tomtom.http.response.ResponseCode.OK
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT
@SpringBootTest(webEnvironment = RANDOM_PORT, classes = [ExtremeStartup, NoWebClient])
class QueryControllerSpec extends Specification {
@LocalServerPort
def port
def http = new HttpClient()
def 'exposes query endpoint'() {
when:
def response = http.get(url: "http://localhost:${port}?q=bar")
then:
response.statusCode == OK
response.body == 'bar'
}
}
(https://github.com/artamonovkirill/extreme-startup/blob/main/groovy/springboot/src/test/groovy/com/github/artamonovkirill/QueryControllerSpec.groovy)
I also didn't any mentions of @LocalServerPort in v3 release notes.
Comment From: artamonovkirill
I figured out it's an issue with Spock Spring module: https://github.com/spockframework/spock/issues/1539
Comment From: bclozel
Thanks for letting us know @artamonovkirill !