Windows Phone 的单元测试状态 [英] State of unit testing for Windows Phone

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

问题描述

我一直在将我的 Google Fu 推向极限,试图找到最推荐/最稳定的设置来为 Windows Phone 应用程序执行 TDD + CI.任何成功地做到这一点的人都可以为我指明正确的方向吗?

I've been pushing my Google Fu to the limits trying to find the most recommended / stable setup for doing TDD + CI for Windows Phone applications. Can anyone who has successfully been doing this point me in the right direction?

这是我想要做的(如果可能的话):

Here's what I want to be able to do (if it's possible):

  • 为不需要手机功能的视图模型和应用服务编写单元测试
  • 通过 Resharper 或 TD.NET 在 Visual Studio 中直接执行测试
  • 从命令行执行单元测试并输出 XML,而不启动模拟器
  • 最好对 SDK 更新具有弹性(就第三方库而言)

由于我想将这个问题作为资源留给其他寻找相同事物的人,因此我希望避免回答以下问题:

Since I'd like to keep this question as a resource to others looking for the same thing, here's what I'd prefer answers to avoid:

  • 不完整或废弃的项目的开源端口
  • 仅在某人的博客上作为附件提供的项目

我还想进行完整的 BDD 式验收测试,但 这完全是另一个问题.

I'd also like to get full BDD-style acceptance tests going, but that's another issue entirely.

推荐答案

我将此答案添加为社区 Wiki,以便其他人可以对其进行修改以使其保持最新.

I'm adding this answer as Community Wiki so that others may modify it to keep it up to date.

意图:运行隔离(无电话功能),通常从 IDE 和持续集成服务器快速执行测试,而不需要模拟器(例如 TDD 视图模型)

我在许多演示文稿中看到的推荐方法涉及在 .NET 4 项目中引用您的源文件并针对这些文件运行测试(引用程序集的桌面等效项).如果您的代码不使用与桌面 BCL 不同的任何 API 并且,您可以处理保持参考项目最新(不会自动添加新文件),这应该足够了.

The method I've seen recommended in a number of presentations involves referencing your source files in a .NET 4 project and running the tests against those (referencing the desktop equivalents of the assemblies). If your code doesn't use any APIs that are different to the desktop BCL and you can deal with keeping the reference project up to date (new files aren't added automatically) than that should be sufficient.

否则,您可以按照以下步骤在桌面 CLR 中执行引用 WP7 程序集的代码:

Otherwise, you can follow the steps below to execute code that references WP7 assemblies in the desktop CLR:

  1. 将测试 Silverlight 4 类库(不是 Silverlight for Windows Phone 项目)添加到您的解决方案
  2. 在类库中,将所有框架引用mscorelib(基本上是System.* 和Microsoft.*)的Copy Local 设置为true
  3. 将此测试库中的引用添加到 NUnit-Silverlight 项目
  4. 将测试库中的引用添加到您的主 Windows Phone 项目,忽略版本警告.
  5. 使用 ReSharper(已测试)或 TestDriven.NET 在 IDE 中运行测试
  6. 使用 最新的 NUnit 版本,传入 /framework=v4.0.
  1. Add a tests Silverlight 4 Class Library (not a Silverlight for Windows Phone project) to your solution
  2. In the class library, set Copy Local for all the framework references except mscorelib (basically System.* and Microsoft.*) to true
  3. Add a reference from this test libary to NUnit.Silverlight.Framework.dll and NUnit.Silverlight.Compatibility.dll from the NUnit-Silverlight project
  4. Add a reference from the test libary to your main Windows Phone project, ignoring the version warning.
  5. Run the tests from in the IDE using ReSharper (tested) or TestDriven.NET
  6. Run the tests from the command line using the standard .NET 2.0 nunit-console.exe from the latest NUnit release, passing in /framework=v4.0.

(由于 WP7 使用 SL3,因此需要上述许多解决方法.一旦 Mango 与 SL4 运行时一起发布,它应该是一个更干净的设置)

(Many of the above workarounds are required because WP7 uses SL3. Once Mango is released with the SL4 runtime, it should be a cleaner setup)

意图:在模拟器上按需和 CI 服务器上运行与代码外部资源(如电话功能和 Web 服务)交互的更长时间运行的测试

更新单元测试 Windows Phone 8 应用程序 将在 Visual Studio 2012 Update 2 中得到官方支持,包括 VS 集成和命令行支持.这些测试在模拟器中运行,因此我将其包含在集成测试中.

UPDATE Unit Testing Windows Phone 8 applications will be official supported in Visual Studio 2012 Update 2, including VS integration and command line support. These tests run in the emulator, so I've included it under Integration Tests.

Silverlight 测试框架的 WP7 端口目前不支持此功能(仅作为从博客下载的版本提供).

This is not currently supported by the WP7 port of the Silverlight test framework (and that only ships as a download from a blog).

与此同时,我创建了一个 codeplex 项目,它添加了一个 MSBuild 任务来启动模拟器并进行整理将结果保存到 XML 文件中.最简单的安装方法是添加 wp7-ci NuGet 包.

In the meantime, I have created a codeplex project that adds an MSBuild task that launches the emulator and collates the results into an XML file. The simplest method installation is to add the wp7-ci NuGet package.

注意:在 Windows Server 上安装 WP7 SDK 需要修改安装程序配置,不支持,但效果很好.

NOTE: Installing the WP7 SDK on Windows Server requires modifying the installer configuration and is not supported, but works well.

意图:在模拟器上运行与手机 UI 交互的端到端自动化测试,无论是按需还是在 CI 服务器上

Expensify(对 SEO 的命名并不好)Windows Phone 测试框架 支持从主机 PC 编写 UI 自动化测试使用 SpecFlow.

Expensify's (poorly named for SEO) Windows Phone Test Framework supports writing UI automation tests from a host PC using SpecFlow.

这篇关于Windows Phone 的单元测试状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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