Currently the JUnit 5 API only allows @BeforeAll
on a method that is static.
So if I do something like this, it will not compile:
@BeforeAll
fun setup() {
MockitoAnnotations.initMocks(this)
mvc = MockMvcBuilders.standaloneSetup(controller).build()
}
In order to have a static method in Kotlin, I have to use companion object
like this:
companion object {
@JvmStatic
@BeforeAll
fun setup() {
MockitoAnnotations.initMocks(this)
mvc = MockMvcBuilders.standaloneSetup(smsController).build()
}
}
这将进行编译,但我无法访问父类中的变量.那么,用Kotlin调用JUnit 5 @BeforeAll
的惯用方法是什么呢?