I'm referencing this question posted here but trying to do the same thing in a kotlin spring boot integration test. I've modified the code to kotlin syntax like so
@DynamicPropertySource
fun properties(registry: DynamicPropertyRegistry) {
registry.add("testApi.baseUrl", {"http://localhost:" + mockWebServer.port})
}
When I run my test, I'm getting an illegalStateException that
@DynamicPropertySource method 'properties' must be static
Trying to add the @JvmStatic annotation creates further problems as well. Is it possible to override a property this way in kotlin? I'd like to point all my webclients in my client classes to my mockwebserver for my integration test.
The Kotlin way of doing this is to use a companion object (caveat: I have not actually tried this)
UPDATE
Here is a working example that sets up the MockWebServer in a Kotlin SpringBootTest