Мой тестовый класс: < /p>
Код: Выделить всё
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class MySpringBootTest {
@LocalServerPort
var port: Int = 0
@Autowired
private lateinit var myService: MyService
@Test
fun testProductionMethod() {
val result = myService.doSomething()
println("Result: $result")
}
}
< /code>
my Application-test.yml: < /p>
my:
custom:
url: http://localhost:{local_port}
Код: Выделить всё
@ConfigurationProperties(prefix = "my.custom")
data class MyCustomProperties(
var url: String = "" // Should be set dynamically
)
Пожалуйста, не отвечайте с помощью сгенерированных AI текстов.
Подробнее здесь: https://stackoverflow.com/questions/794 ... st-with-ra