Kotlin Spring 引导单元测试 - 添加 @TestExecutionListeners 不会注入依赖项
Kotlin Spring Boot Unit Test - adding in @TestExecutionListeners doesn't inject dependencies
我正在尝试使用 Flyway Test Extensions 库,其说明之一是添加:
@TestExecutionListeners({DependencyInjectionTestExecutionListener.class,
FlywayTestExecutionListener.class })
所以在 Kotlin 中,我有一些类似的东西:
@RunWith(SpringRunner::class)
@TestExecutionListeners(DependencyInjectionTestExecutionListener::class,
FlywayTestExecutionListener::class )
class MyControllerTest {
@Autowired
lateinit var dataSource : DataSource
}
但出于某种原因,当我尝试 运行 中的 class 测试时,我收到一条错误消息,指出 lateinit 属性 尚未初始化。
我需要什么特别的东西have/do才能让它正常工作吗?
好吧,我终于找到了 1 个帮助我解决问题的 post:
我需要的注释是:
@TestExecutionListeners(
listeners = [FlywayTestExecutionListener::class],
mergeMode = TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS
)
我正在尝试使用 Flyway Test Extensions 库,其说明之一是添加:
@TestExecutionListeners({DependencyInjectionTestExecutionListener.class,
FlywayTestExecutionListener.class })
所以在 Kotlin 中,我有一些类似的东西:
@RunWith(SpringRunner::class)
@TestExecutionListeners(DependencyInjectionTestExecutionListener::class,
FlywayTestExecutionListener::class )
class MyControllerTest {
@Autowired
lateinit var dataSource : DataSource
}
但出于某种原因,当我尝试 运行 中的 class 测试时,我收到一条错误消息,指出 lateinit 属性 尚未初始化。
我需要什么特别的东西have/do才能让它正常工作吗?
好吧,我终于找到了 1 个帮助我解决问题的 post:
我需要的注释是:
@TestExecutionListeners(
listeners = [FlywayTestExecutionListener::class],
mergeMode = TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS
)