✅ unit testing ViemModels
I am very new to unit testing, and I have a typical example where I have a constructor with 4 services 3 of which is DI and one concrete generic for navigation
E.g public
I have be having problem testing because I need to create a moq of E<F> and because of the way it is setup it's hard to abstract to interface.
Does it make sense to create IViewModel
And then have
Class ViewModel:IViewModel
And mock IViewModel instead? Is this the recommended approach? Is this good or bad ?
6 Replies
u cant mock the view model if u want to test the view model
u will have to mock the services and the navigation.
I'd honestly never test a VM, only the services themselves if they belong to the same codebase ofc
question is why its hard to make an interface for navigation
There is not a lot you can/should be testing in the VM directly, ideally it's just an adaptation layer that might change a lot depending on the UI, so it might actually be disadvantageous to test it
@LPeter1997 @cap5lut it's hard because of the way the MVVM navigation is setup based on singletonSeans videos
I will post a link to a GitHub, I have showing the navigation snippet
I have no issues mocking the services as theres proper DI in place and constructor injection but can't for the navigation as it's concrete
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.