Kotlin单元测试:withContext块中没有与模拟的交互

时间:2019-06-24 21:42:38

标签: unit-testing kotlin mocking mockito kotlin-coroutines

我在单元测试中模拟了一个类。我想检查我的被测课程是否与之互动。但是,由于它位于withContext { } block

中,因此无法检测到任何交互

当我删除withContext代码时,测试将检测到交互并通过。但是,我需要用上下文将其包裹起来。

// I init the mocked object like so
val model: QRCodeModel = mock()

// I make sure I return some data when the mocked object is called
whenever(model.getQRCode()).thenReturn(bitmap) 

// this is always failing when checking how many times it was interacted with
verify(model, times(1)).getQRCode() 

0 个答案:

没有答案