r/androiddev•
Kranuh

What are the immediate disadvantages of using Robolectric instead 'normal' unit tests with Mockito.

Discussion

So our team is having a discussion. We are building our app using an MVVM architecture, and I am proposing to keep our ViewModels clean from Android related code. Now some of my colleagues oppose this, saying this is too much of a restriction and they should be allowed to use Android related code, such as Context in the ViewModel when necessary.

My first go to argument would be; well that creates ViewModels that we can't test. But one of my colleagues told me that Robolectric doesn't need to actually run on a device since it only mocks the SDK. So my question is: What is the real disadvantage of using Robolectric for unit tests? If there are no immediate disadvantages, is my argument still valid? Why not allow the Context to be used once in a while if it is really necessary? We could test it with Robolectric anyway.

Posted May 24, 2017, 7:38 AM UTC

726
Loading comments…