Open iamareebjamal opened 6 years ago
@iamareebjamal How would you recommend writing unit tests for those ViewModels which use Realm ? Should we mock the realm database ?
Right now the constructor of these ViewModel initialises the Realm instance For eg.
public TrackSessionsActivityViewModel() {
realmRepo = RealmDataRepository.getDefaultInstance();
}
We can't create a mock Realm in-memory instance to test this ViewModel. I think we should introduce dependency injection in the project so that we could pass the Realm Instance as a parameter in the Constructor and then only we could test our ViewModels by mocking the Realm Database inside our tests.
Right now it'll require a lot of effort to do so. Create a package protected method to set RealmRepo and set mock implementation through it
Also, let's focus on pre-assigned issues first, because we need to move away from maintenance mode to feature development mode. We are very behind in implementing the API
Ok, will do this after those issues.
@srv-twry When you implement one such PR for a test case for a ViewModel, then reopen the issue and link since it is required to have an aligning issue with PR, and this issue cannot be solved in one PR.
Actual Behaviour
To be done after #2016 There are no unit tests on common code for ViewModels
Expected Behaviour
Unit Test coverage for every ViewModel should aim to be 100%
Parent Issue : #2014