Programming Kotlin: Issues in async() unit test (369, 370)

Hi sir,

I request your help with the below issue I came across while learning about unit testing.

I replicated the unit test example with name ‘getAirportStatus calls getAirportData asynchronously’ in the book, and I got the below error when I run the test

Can’t instantiate proxy for class kotlinx.coroutines.Deferred
io.mockk.MockKException: Can’t instantiate proxy for class kotlinx.coroutines.Deferred

I have a couple of questions regarding unit testing:

  1. What causes the above error? What does “Can’t instantiate proxy” actually mean?
  2. It is mentioned earlier in the book ‘suspend’ method calls must be done in coroutine context in the unit test, i.e, within runBlocking{}. How come getAirportStatus() method, a suspend method, is called without a runBlocking in the above test? What influence does ‘coEvery’ has on this aspect?

Kindly advise.

Thanks,
Harry