1

I saw similar post: How to mock method call and return value without running the method?

I am wondering if there is similar method we can use in mockK? something like: doReturn.when(mock).method in mockito

I saw this question before Equivalent of doReturn(x).when(y)... in mockk?

But the answer is: every (method) returns (value)... which is not what I want. Because every(method) will actually run the method

dosu
  • 41
  • 2
  • 8

1 Answers1

2

With “every” not executes the original method if you not wish, “every” invalidate the call to original and returns the data declared for will returned.

Example:

every { yourMock.getData() } returns yourData

If you want call original method can use:

every { yourMock.getData() } answers { callOriginal() }
Igor Román
  • 186
  • 1
  • 5