In Java I can define TestConfiguration in nested class
class Example {
@Nested
@SpringBootTest
public class ExampleNestedTest {
@TestConfiguration
public static class TestConfig {
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
}
}
}
However in Kotlin, the nested test must be inner class, and the nested class in the inner class must also be a inner class
I tried this but got a compiler error
class Example {
@Nested
@SpringBootTest
inner class ExampleNestedTest {
@TestConfiguration
class TestConfig { // This give error 'Class' is prohibited here.
@Bean
fun restTemplate(): RestTemplate {
return RestTemplate()
}
}
}
}
I tried adding inner
to TestConfig
but the bean function will not run.
class Example {
@Nested
@SpringBootTest
inner class ExampleNestedTest {
@TestConfiguration
inner class TestConfig {
@Bean
fun restTemplate(): RestTemplate { // This bean will not be created as the function will not run
return RestTemplate()
}
}
}
}
Any idea how to make this to work?