Why is mockkConstructor() not working on the every block?

142 Views Asked by At

I'm trying to mock a constructor of a class that is a lazy variable of the class I'm testing:

private val manager by lazy {
   manager(Data(ID_ADMIN, MANAGER_CODE), context)
}

I have the mockk() variable in my teste class, now I'm trying to use mockkConstrutor() to stub the method and return my mocked class to the class I am testing, but it's just not working:

Private val manager: Manager by lazy {

mockk<Manager>()
}
mockkConstrutor(Manager::class)

every {

 anycontructed<Manager>()
} answer {

  manager 
}

I keep getting

Missing mocked calls inside every { ... } block: make sure the object inside the block is a mock io.mockk.MockKException: Missing mocked calls inside every { ... } block: make sure the object inside the block is a mock at io.mockk.impl.recording.states.StubbingState.checkMissingCalls(StubbingState.kt:14) at io.mockk.impl.recording.states.StubbingState.recordingDone(StubbingState.kt:8) at io.mockk.impl.recording.CommonCallRecorder.done(CommonCallRecorder.kt:47) at io.mockk.impl.eval.RecordedBlockEvaluator.record(RecordedBlockEvaluator.kt:60) at io.mockk.impl.eval.EveryBlockEvaluator.every(EveryBlockEvaluator.kt:30) at io.mockk.MockKDsl.internalEvery(API.kt:92) at io.mockk.MockKKt.every(MockK.kt:98)

from Mockk, it asks me if I'm sure the object inside the every block is a mock. I'm using Kotlin 1.3.20 and Mockk 1.10.6.

To return my mockked instance of the object when the construtor is called, just like whenNew() of PowerMockito

0

There are 0 best solutions below