What do you think is the best combination for tes...
# test
s
What do you think is the best combination for testing android application with kotlin? Spek vs KotlinTest, mockk vs mockito-kotlin???? Thanks
d
My personal opinion. I try to stay as much as possible with tried and tested frameworks when they don't bring huge disadvantages. So standard junit + hamcrest + kotlin mockito. And kotlin mockito I see as a necesarry evil since standard mockito does not play nice with kotlin currently. Which might change in the future. Mockk does too much in my opinion. The purpose of the testing framework should be also to lead the people to good software design and when you can mock static stuff like mockk (and it can do moch more) - thats the opposite. I would only use it to test mega legacy code and only to refactor it asap
i
I have used JUnit + Mockito + mockito-kotlin + Kluent (more expressive assertion framework then hamcrest) and Spek + Mockito + mockito-kotlin + Kluent KotlinTest was a bit problematic for me (but it was sometime ago, so mabye now it works) My old article: https://blog.babylonhealth.com/migrating-java-junit-tests-into-kotlin-6ded57597666
s
Thanks you two for the answers
o
@Daniel just a few words to defend MockK First thing MockK is indeed a library, not framework, so doesn't limit/mandate how you write the code. All features are implemented for only one purpose to do mocking in Kotlin possible and simple. mockkStatic is needed because you can have top-level functions/extension functions which you are able to mock only with static mocking. Then mockkObject is needed for objects and so on. You can check https://medium.com/@oleksiypylypenko/mockk-intentions-dbe378106a6b for more details
a
+1 to @Daniel, start with standard tools When you face problems, like too much repetitive code, don't feel as productive, etc then it's a good time to try alternatives
d
Don't get me wrong, I really apprecheate the effort and love put into mockk. A mocking lib just for kotlin really is awesome. Its just my opinion that the feature set of mockito is encouraging good coding habits. For example the mockkStatic - you shouln't need to mock static stuff or top level functions in code that is well decoupled. The stuff you mock should live in its own small word (dependency) and be rarely grobally (statically) accessible
1
o
No worries, I understand both sides