Enhancements request
The current syntax to inject a bean in a test is somehow confusing: it requires a field annotated with @TestBean and also a static method. When you use Kotlin, you also need a companion object and @JvmStatic
Ideally, you only need a non static method annotated with @TestBean. This is also symmetric to a regular bean definition.
@SpringBootTest
class CurrentServiceTest {
@TestBean lateinit var myBean: MyBean
@Test
fun testMyService(@Autowired myService: MyService) {}
companion object {
@JvmStatic
fun myBean(): MyBean = MyTestBean()
}
}
@SpringBootTest
class SimplifiedServiceTest {
@Test
fun testMyService(@Autowired myService: MyService) {}
@TestBean
fun myBean(): MyBean = MyTestBean()
}
Enhancements request
The current syntax to inject a bean in a test is somehow confusing: it requires a field annotated with
@TestBeanand also a static method. When you use Kotlin, you also need a companion object and@JvmStaticIdeally, you only need a non static method annotated with
@TestBean. This is also symmetric to a regular bean definition.