This message was deleted.
# android
s
This message was deleted.
😶 1
w
Hi @teddy, there are some red flags about this View model that makes it harder to test, mainly how the service is instantiated inside the ViewModel. You could technically still test it by what is returned on the live data but I suggest that you take a look at the testing training for view models to reach a better solution (https://developer.android.com/codelabs/advanced-android-kotlin-training-testing-basics)
👍 1
a
I’m curious why a screenshot and not a copy paste in the thread, be easier to read
t
It is just a service class implementing from a ServiceListner class having 2 function onError and onSuccess as callback functions when calling service.getGovState. I don’t even see any DI library like koin, dagger or hilt in the project. They are just doing them manually like that.
What I want to test is to set the onError with any specific parameters, and then test to compare the value of the isOOBTACustomer with a given value. But I dont know how to do it with a mock of isOOBTACustomer , and set the params for service.onError (maybe not this way)
x
@teddy It sounds like you're working on some old code. You should move the service creation code to outside the view model, and test it independently. Side note, I often try to avoid making my classes depending directly on the SDK component such as Context, or Application, it makes things very hard to test. I often move such dependency into a single-purpose class to "quarantine" the dependency on SDK components, and make my ViewModel depend on that class instead. That way, the dependency on SDK component is isolated, and can be tested more easily, while the ViewModel can be tested with a mock implementation/object of such quarantining class.
👍 1