Unit Testing ViewModel in Xamarin Forms having parameter in Constructor

I am working on writing Unit Test for my Xamarin.Forms Solution. In my ViewModel, all my ViewModel are inherited from BaseViewModel with INavigation as a parameter.

public TestViewModel(INavigation navigation) : base(navigation)
{
this.navigation = navigation;
//Further code
}

Now i am facing issue with initializing my ViewModel from UnitTest Class. How can i initialize and pass object of INavigation to while initializing ViewModel object in UnitTest class?

Answers

  • JohnHardmanJohnHardman GBUniversity mod
    edited July 2018

    @ArunGupta.7607 - Different people use different terminology, but check out mocking, stubbing and faking in unit tests. Google should provide plenty of answers for those terms, but alternatively read the book "The art of unit testing with examples in C#" by Roy Osherove. You might also want to look at tools such as RhinoMocks, Moq or NSubstitute. If you are new to mocking and stubbing, I'd recommend reading that book.

Sign In or Register to comment.