Testing ViewModels in MVVMCorss

蹲街弑〆低调 提交于 2019-12-25 04:13:38

问题


I have just started working with MVVMCross for a cross platform app and I am having a hard time figuring out how to test my ViewModels. I tried following the testing done in TwitterSearch and ran into problems. Specifically in the MockSetup.cs I found that in the latest version of MvvmCross there no longer seems to be a IMvxViewDispatcherProvider but that is ok because I think its functionality has been rolled up into the IMvxViewDispatcher. However, when actually setting up the dipatcher for my test cases there is no RequestNavigate method for the dispatcher anymore and I can not find an implementation of MvxShowViewModelRequest. So I can not actually get any tests for my ViewModels to work.


I also tried to follow the testing here http://slodge.blogspot.com/2012/10/testing-viewmodels-in-mvvmcross.html but again ran into issues with missing MvxOpenNetCfServiceProviderSetup.

So in summary, my issue has been getting a MockSetup working so that I can test my ViewModels. If I could just be pointed in the right direction on the dispatcher, I think that would help.


回答1:


It looks like you are trying to test an mvvmcross v3 application using mvvmcross vnext objects.

The updated twitter search test for v3 is at https://github.com/slodge/MvvmCross-Tutorials/tree/master/Sample%20-%20TwitterSearch/TwitterSearch.Test

This test uses a single special mock object: https://github.com/slodge/MvvmCross-Tutorials/blob/master/Sample%20-%20TwitterSearch/TwitterSearch.Test/Mocks/MockMvxViewDispatcher.cs

The role of this mock is just currently:

  • to provide a very simple main thread (it uses the current thread)
  • to provide simple storage for any navigation requests.

You can see it used in:

  • https://github.com/slodge/MvvmCross-Tutorials/blob/master/Sample%20-%20TwitterSearch/TwitterSearch.Test/HomeViewModelTest.cs


来源:https://stackoverflow.com/questions/16672122/testing-viewmodels-in-mvvmcorss

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!