Connecting expansion function in Kotlin

How to mock Kotlin extension function using Mockito or PowerMock in tests? Since they are solved statically, if they are checked as calls to static methods or as non-static?

+5
source share
1 answer

First of all, Mockito knows nothing of the constructive language constructs of Kotlin. In the end, Mockito will look in bytecode. Mockito can only understand what he finds there, and what looks like a Java language construct.

Meaning: To be really sure, you can use javap to demonstrate compiled class files to determine the exact names / signatures of the methods you want to make fun of.

And, obviously: when this method is static, you should use PowerMock or JMockit; if not, you should prefer with Mockito.

From a java point of view, you are simply avoiding mocking static things; but, of course, everything becomes really interesting, now that different languages ​​with different ideas / concepts are combined.

+4
source

Source: https://habr.com/ru/post/1268578/


All Articles