0
我已經使用JMockit很長一段時間了,我非常喜歡它。但是,我遇到了一個我似乎無法解決的問題。查看下面的代碼片段,瞭解一些Kotlin測試代碼,測試Kotlin生產代碼。使用JMockit和Kotlin捕獲對象
@Injectable
lateinit var experimentStorage: ExperimentStorage
...
val experimentCaptor = mutableListOf<Experiment>()
object : Verifications() {
init {
experimentStorage.save(withCapture(experimentCaptor))
}
}
當我運行我的測試,我得到以下錯誤:
java.lang.IllegalStateException: withCapture(experimentCaptor) must not be null
我100%肯定我的生產代碼正確行使存儲,因爲當我更換捕獲像下面,我測試成功:
object : Verifications() {
init {
experimentStorage.save(withAny(experiment))
}
}
有沒有人有使用JMockit(1.28)在Kotlin中捕獲參數的經驗?我究竟做錯了什麼?我想它與init
塊有關,因爲在Java中,您將使用靜態空間...