Tuan Kiet

05/28/2019, 6:22 AM
anyone here using inline class with mockito before? Mockito gets confused when I’m trying to mock a method with the return type is an inline class. It basically says something like
can not mock this method with return type String but got Url instead

Stephan Schroeder

05/28/2019, 8:40 AM
which version of mockito are you using? Version2.25.0 seems to contain improvements regarding inline:
Mockito 2.25.0 had an important feature added for anyone using mockito-inline. In particular anyone using Kotlin (which demands using mockito-inline) and PowerMock (which exasperates the problem even more) will want to add this to all of their test classes to avoid a large memory leak
that being said, it might be a good idea to switch (or introduce in parallel for all new tests) mockk, which is a mocking library written in Kotlin. It can even mock final classes, which is the default in Kotlin and doesn’t collide with the Kotlin syntax (I ran into the issue of mockito’s when-function colliding with Kotlin’s when keyword yesterday, when working with a project that I recently converted from Java to Kotlin. There is a workaround for that, but still, it’s annoying. So while I don’t want to rewrite all the old tests, i decided to switch to mockk for everythin new. (for completeness: mockito2 has expermental support for mocking final classes as well.)
👍 1


05/28/2019, 3:32 PM
I wouldn't use mockito at all for Kotlin. I'd go for #mockk