在MVVMCorss中测试ViewModel [英] Testing ViewModels in MVVMCorss

查看:87
本文介绍了在MVVMCorss中测试ViewModel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始为跨平台应用程序使用MVVMCross,但我很难确定如何测试我的ViewModels.我尝试按照TwitterSearch中的测试进行操作,但遇到了问题.特别是在MockSetup.cs中,我发现在最新版本的MvvmCross中似乎不再有IMvxViewDispatcherProvider了,但这没关系,因为我认为它的功能已经汇总到IMvxViewDispatcher中.但是,当实际为我的测试用例设置dipatcher时,不再有RequestNavigate方法用于分派器,并且我找不到MvxShowViewModelRequest的实现.因此,我实际上无法为ViewModels进行任何测试.

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.


我还尝试在此处进行测试 http://slodge.blogspot .com/2012/10/testing-viewmodels-in-mvvmcross.html ,但再次遇到缺少MvxOpenNetCfServiceProviderSetup的问题.


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.

因此,总而言之,我的问题一直是使MockSetup运行,以便我可以测试ViewModel.如果我能向调度员指出正确的方向,那会有所帮助.

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.

推荐答案

您似乎正在尝试使用mvvmcross vnext对象测试mvvmcross v3应用程序.

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

针对v3的更新的Twitter搜索测试位于

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

此模拟的角色目前是:

  • 提供一个非常简单的主线程(它使用当前线程)
  • 为任何导航请求提供简单的存储.

您可以在以下位置看到它的使用

You can see it used in:

这篇关于在MVVMCorss中测试ViewModel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆