尝试通过模拟来模拟OffsetDateTime.now(),但会抛出
Missing calls inside every { ... } block
我尝试过:
staticMockk<OffsetDateTime>().mock().run {
val mockTime = OffsetDateTime.now()
every { OffsetDateTime.now() } returns mockTime
// test
}
也尝试过:
mockkStatic(OffsetDateTime::class)
val mockTime = OffsetDateTime.now()
every { OffsetDateTime.now() } returns mockTime
答案 0 :(得分:0)
对我来说还可以。请考虑使用最新版本(1.8.8或1.8.8.kotlin13),或者如果它不起作用,请报告错误。
这是我的代码:
mockkStatic(OffsetDateTime::class)
val date = OffsetDateTime.of(
2012,
10,
10,
10,
10,
10,
10,
ZoneOffset.UTC
)
every {
OffsetDateTime.now()
} returns date
println(OffsetDateTime.now())