【发布时间】:2020-06-25 07:00:29
【问题描述】:
只是把这个扔在那里,希望除了明显低于标准的答案之外还有一个干净的答案。
我有一个类会在 const 中定义的一段时间后触发。在我的测试中,我希望那个时间更小,以便测试运行得更快。有没有办法在测试中覆盖 const?
目前丑陋的解决方案是我正在更改代码,以便将延迟时间作为参数传递,这很丑陋,因为该参数只会在测试中使用。
const val DELAY_BEFORE_CODE_MILLIS: Long = 300000
class CheckValues(
private val vertx: Vertx
) {
fun doStuff() {
vertx.setTimer(DELAY_BEFORE_AGGREGATION_CHECK_MILLIS) {
<code i want to test>
}
...
}
【问题讨论】:
标签: unit-testing kotlin timer constants