https://kotlinlang.org logo
#android
Title
# android
n

nebojsa.vuksic

02/21/2017, 10:24 PM
Hi guys, can somebody tell me how do you unit test extension functions? Do you verify them as standard method calls or as static methods calls?
m

mg6maciej

02/21/2017, 10:28 PM
If you unit test a function, doesn't matter if it is extension, top-level or static in java, just call it and check result.
n

nebojsa.vuksic

02/21/2017, 10:35 PM
I agree, but can junit4 test static method? I need power mock for that, don't I ?
j

Jorge Castillo

02/22/2017, 7:51 AM
If it's just about testing the function itself, just call the function! Retrieve the result on a variable and assert to it. If you are trying to test a class which is using the extension function, just think that you call those functions over an object instance, not as static functions. So you shouldn't have any difference either on testing a class with standard function calls inside of it's methods.
👍 1
3 Views