惩戒在Windows商店应用 [英] Mocking in Windows store app

查看:173
本文介绍了惩戒在Windows商店应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是可能首先与谁在Windows商店应用程序嘲讽为测试目的的交易。我想测试我的ViewModels和使用一些嘲讽框架来嘲笑他们。当然,所有可用的(公共)框架无法在Windows应用商店的应用项目中使用。我有一个想法如何解决这个问题,但我不知道这是最好的解决办法。我的解决方案包含这些项目。主要的一点是表示层划分为两部分:

I'm not probably first who deals with mocking in windows store application for testing purpose. I would like to test my ViewModels and to use some of mocking frameworks to mock them. Of course, all of available (common) frameworks are not able to use in windows store application project. I have one idea how to solve it but I'm not sure that it is best solution. My solution consists of these projects. Main point is to divide presentation layer to two parts :

展示 - Windows应用商店的应用程序

Presentation - Windows store application

启动包含不需要被测试只呈现次(页)和表示部件的项目。该项目具有参考PresentationLogic

Start-up project that contains only presentation views (Pages) and presentation parts that do not need to be tested. This project has reference to PresentationLogic.

PresentationLogic - 便携式类库,目标:Windows应用商店的应用程序,.NET框架4.5

PresentationLogic - Portable Class Library, Targets : Windows store application, .NET Framework 4.5

该项目包含这样的应进行测试

This project contains all presentation logic like ViewModels, Converters, Helpers etc. that should be tested

单元测试 - 类库

包含单元测试的能力,从PresentationLogic嘲讽所有接口古典类库。此库具有参考PresentationLogic。

Classical class library containing unit tests with ability to mocking all interfaces from PresentationLogic. This library has reference to PresentationLogic.

这是很奇怪的视图和视图模型划分为两层,但我没有找到这个另一种解决方案。

It is quite strange to divide Views and ViewModel to two layers but I did not find another solution for this.

你有没有请任何想法如何处理这个问题?样表示层到另一个项目类型的两层分裂?它可能会导致进一步的发展的一些问题?

Do you have please any idea how to deal with this problem? What about splitting of the presentation layer to the two layers of another project type? Can it cause some problems in further development?

推荐答案

您在正确的轨道上是绝对。有两点要注意:

You're definitely on the right track. A couple of notes:

使用MvvmLight(这是可以移植的,顺便说一句),您可以使用自己内置的服务定位和DependencyInjection做的事情就像注入测试控制器针对特定平台的过程。这将允许一吨的逻辑来保持便携,通过定义接口和注入的实现(包括嘲笑实现)。

Using MvvmLight (which is available portable, by the way), you can use their built-in ServiceLocator and DependencyInjection to do things like inject test controllers for platform specific processes. This will allow a ton of your logic to remain portable, by defining interfaces and injecting the implementations (including mocked implementations).

根据您的PCL,你可能会(在我的经验)不能包括转换器(从的IValueConverter 继承)在PCL。该库是平台(尤其是Silverlight的/的WinRT / 4.5 /单声道)之间一般是不同的,因为他们是最常见的用途是UI,如装订处理。同样的,喜欢的东西 DataTemplateSelector 秒。这些将有可能被改写为大部分的平台(虽然幸运的是,这并不难,仍然是相当多的复制粘贴)。

Based on your PCL, you will likely (in my experience) be unable to include Converters (which inherit from IValueConverter) in your PCL. The library is generally different between the platforms (especially Silverlight/WinRT/4.5/Mono), as the most common use for them is for UI, such as binding processing. Same with things like DataTemplateSelectors. These will likely have to be rewritten for most of your platforms (though luckily that's not that hard and is still quite a bit of copy-paste).

至于其余它,你有它发现的。你可以有你的演示应用是通用,因此它可以涵盖Windows应用商店和Windows Phone应用商店的应用程序。绝大多数的商业逻辑的应该是在你的PCL。因为有时它只是不可避免的要把VM里面的一些UI辅助的易用性,您可能会遇到这方面的一些问题。如果这是绝对必要的,可以让你随身的ViewModel 摘要,然后用上面提到的依赖注入插入特定于平台的实现。这是很容易做到的和非常有用的。

As to the rest of it, you have it spot on. You can have your Presentation app be Universal, so it can cover both Windows Store and Windows Phone Store apps. The vast majority of your 'business logic' should be in your PCL. You may run into some issues in this regard because sometimes it's just unavoidable to want to put some UI helpers inside the VM for ease of use. If this is absolutely necessary, you can make your Portable ViewModel abstract, then use the Dependency Injection mentioned above to insert the platform-specific implementations. It's quite easy to do and very useful.

一件事,你缺少的是UI测试。你可以将它们包含在你的单元测试类库,或将其他编码的UI测试类库,给你。

The one thing that you are missing is UI tests. You could include them in your unit test class library, or make another Coded UI Test class library, up to you.

无论如何,希望帮助。

这篇关于惩戒在Windows商店应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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