https://kotlinlang.org logo
#mockk
Title
# mockk
o

oleksiyp

07/17/2019, 2:31 PM
I thought mockk mocks are strict by default, but mockito are not, but dont want to go deeper to compare it. Not near PC
m

Mike

07/17/2019, 3:21 PM
Mockito uses 'strict' to mean a slightly different thing than MockK's usage of 'strict'. That's the short answer. And in 2.0, Mockito added strictness. When you have a chance, I documented differences here: http://mikewilkes.ca/2018/06/23/kotlin-testing-with-mocks/ Mockito:
>> Using Mockito Extension in JUnit Jupiter, and annotation based mocking results in strict checking. Basically, if no expectations are defined on a mock object, it will act like a stub. This means it will return a reasonable default for any calls.
As soon as an expectation is defined, the Mock becomes strict. It will report any calls that don’t match a defined expectation AND will report any expectations that were defined, but not called. This is like defining verify on every interaction, and adding a verify no more interactions. There is no option to ensure a mock is actually used as a mock until at least one interaction is defined. The only way to ensure all mock calls are defined would be to call verify with noMoreInteractions on all mocks at the end of the test.
That's a bit different from MockK's definition.
👍 1
a

amatkivskiy

07/18/2019, 5:30 AM
@Mike Thanks for info 🤘 Let me check this behaviour
@oleksiyp is there any plans to have something like this in Mockk?
m

Mike

07/18/2019, 10:40 AM
If you're looking at mockk, then this isn't truly relevant. I've discovered that JUNIT or Mockito has been fixed so that the JUNIT extension works using mock() now. Need to update post hut haven't yet.
a

amatkivskiy

07/18/2019, 12:35 PM
seems I need to migrate to Mockito from Mockk
m

Mike

07/18/2019, 12:52 PM
Depends on what you want. Mockk definitely has some features Mockito doesn't, and it's a little more fluid in its definitions. And Mockk's strict provides some value that Mockito's doesn't. If you define a mock in Mockk as strict, and something calls that mock without an explicit definition, Mockk will fail. Mockito will return default value for call regardless, and only reports mock expectations defined, but not called during this test run. For me, I'd like both of those covered under strict mocks, but it's not for everyone.
o

oleksiyp

07/18/2019, 12:54 PM
Can you please drop a ticket? You need automatic check? Or caliing something alike
everythingUsed
at the end is ok?
Just one line of exactly what you need, dont need to be very descriptive
Because I belive mockito doing some hacks to check if all stubbed calls are used
Sorry again, I am on vacation and still not able to capture 100% thing you need
That's fine. I'm about to go on vacation too, so enjoy yours.
o

oleksiyp

07/18/2019, 1:01 PM
Thanks
m

Mike

07/18/2019, 1:02 PM
I may take a look at the MockitoExtension to see how it's accomplishing it, and see if that can fit into MockK. If I do, and discover anything, I'll share on the ticket.
o

oleksiyp

07/18/2019, 1:02 PM
Ok
a

amatkivskiy

07/18/2019, 1:13 PM
For me, I’d like both of those covered under strict mocks, but it’s not for everyone.
Thats what I am looking for
126 Views