https://kotlinlang.org logo
Title
g

gyl

06/05/2018, 3:36 PM
Hello everyone, Did someone managed to unit test
object
classes ? We would like, for each test, re init a
lateinit var foo
property with different values a on our singleton, but actually, once it is initialized once, we found no way to reinit the singleton. Sorry for my english..
a

Andreas Sinz

06/05/2018, 4:06 PM
What do you mean with initalize? Its a
var
, so you can just set a new value
g

gildor

06/05/2018, 5:18 PM
You can mock object using static mocking with Mockk http://mockk.io/ Or something like Power Mock
But my (and not only my) opinion that you shouldn’t do this. If you want to mock object, top level function, constant etc you are doing something wrong and should think about architecture of your testable class.
👍 2
2
g

gyl

06/06/2018, 5:00 AM
Thank you @gildor ! Yeah, you're right. It is just to go a bit further in unit tests with Kotlin, trying to see what's possible and not. Thank you for your time.