anyone here using inline class with mockito before...
# announcements
t
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
s
which version of mockito are you using? Version2.25.0 seems to contain improvements regarding inline:
Copy code
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
https://github.com/mockito/mockito/wiki/What%27s-new-in-Mockito-2
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.) https://mockk.io/
👍 1
l
I wouldn't use mockito at all for Kotlin. I'd go for #C9EJFT6DB