Unit test Prism navigation

前端 未结 1 1307
予麋鹿
予麋鹿 2021-01-15 03:05

I\'m creating an application using Prism and Xamarin Forms. I want to unit-test my view models.

I have a command that navigate to a page. I want to assert that the n

相关标签:
1条回答
  • 2021-01-15 03:54

    What you are proposing is to unit test Prism not your code. Unit testing your ViewModel is a good thing, but you only need to provide a Mock that provides you a way to verify that the navigation string/parameters you expected were valid. For example your Mock may look something like:

    public class MockNavigationService : INavigationService
    {
        public string LastNavigationString { get; private set; }
        public NavigationParameters LastNavigationParameters { get; private set; }
    
        public Task NavigateAsync(string name, NavigationParameters parameters, bool? useModalNavigation = null, bool animated = true)
        {
            LastNavigationString = name;
            LastNavigationParameters = parameters;
            return Task.FromResult(0);
        }
    }
    

    What it sounds like to me is that what your real goal is though is not to run a unit test but to do a UITest that could validate the navigation and User experience with your application.

    0 讨论(0)
提交回复
热议问题