Spring boot Kotlin Spring Boot单元测试-添加@TestExecutionListeners不';t注入依赖项
我正在尝试使用Flyway测试扩展库,其中一个说明是添加:Spring boot Kotlin Spring Boot单元测试-添加@TestExecutionListeners不';t注入依赖项,spring-boot,kotlin,dependency-injection,junit4,Spring Boot,Kotlin,Dependency Injection,Junit4,我正在尝试使用Flyway测试扩展库,其中一个说明是添加: @TestExecutionListeners({DependencyInjectionTestExecutionListener.class, FlywayTestExecutionListener.class }) 因此,在科特林,我有一些大致的想法: @RunWith(SpringRunner::class) @TestExecutionListeners(Dependen
@TestExecutionListeners({DependencyInjectionTestExecutionListener.class,
FlywayTestExecutionListener.class })
因此,在科特林,我有一些大致的想法:
@RunWith(SpringRunner::class)
@TestExecutionListeners(DependencyInjectionTestExecutionListener::class,
FlywayTestExecutionListener::class )
class MyControllerTest {
@Autowired
lateinit var dataSource : DataSource
}
但由于某种原因,当我尝试在该类中运行测试时,我得到一个错误,表明lateinit属性尚未初始化
有什么特别的事情需要我去做吗?好吧,我终于找到了另外一个帮助我解决这个问题的帖子: 我需要的注释是:
@TestExecutionListeners(
listeners = [FlywayTestExecutionListener::class],
mergeMode = TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS
)