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

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

问题描述

我一直在努力将我的Google Fu设置为尝试找到最推荐/稳定的设置为Windows Phone应用程序执行TDD + CI的限制。



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




  • 为不需要手机功能的视图模型和应用程序服务编写单元测试

  • 在Visual Studio中直接执行测试通过Resharper或TD.NET

  • 使用XML从命令行执行单元测试,而不启动模拟器

  • 作为第三方库的SDK更新



由于我想将此问题作为资源保留给其他人




  • 打开未完成或已放弃的项目的源端口
  • b $ b
  • 只能在某人的博客上以附件形式提供的项目



我也想获得完整的BDD-样式验收测试正在进行,但这是另一个问题

解决方案

我将此答案添加为社区Wiki,以便其他人可以修改它

意图:运行隔离(无电话功能) ),经常从IDE和Continuous Integration服务器快速执行测试,而不需要仿真器(例如。 TDD视图模型)



我在一些演示中推荐的方法涉及在.NET 4项目中引用源文件并运行测试(引用组件的桌面等效项)。如果您的代码不使用与桌面BCL 不同的任何API,您可以处理保持参考项目为最新(不会自动添加新文件)的程序。



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



<
  • 向您的解决方案添加测试Silverlight 4类库(而不是适用于Windows Phone的项目)
  • $ / $>
  • 在类库中,设置将所有框架引用(除了mscorelib )(基本上是System。*和Microsoft。*)复制到 true

  • 将此测试库中的引用添加到 NUnit.Silverlight.Framework.dll NUnit.Silverlight.Compatibility.dll NUnit-Silverlight项目

  • 将测试库中的引用添加到您的主Windows Phone项目,忽略版本警告。

  • 从IDE运行测试使用ReSharper(测试版)或TestDriven.NET

  • 使用标准.NET 2.0 nunit-console.exe 最新的NUnit版本传入 / framework = v4 .0

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



    集成测试



    > Intent:运行更长时间运行的测试,与在模拟器上的代码外部资源(如电话功能和Web服务)进行交互,无论是按需还是CI服务器



    UPDATE 单元测试Windows Phone 8应用程序将在Visual Studio 2012 Update 2中官方支持,包括VS集成和命令行支持。这些测试在模拟器中运行,所以我将它包含在Integration Tests中。



    这不是Silverlight测试框架的WP7端口目前支持的



    在此期间,我创建了一个 codeplex项目添加一个MSBuild任务,启动仿真器并将结果整理到一个XML文件中。最简单的方法安装是添加 wp7-ci NuGet软件包



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



    < h1>接受/系统测试

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



    Expensify(为SEO命名不当) Windows Phone测试框架支持使用SpecFlow从主机PC编写UI自动化测试。


    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):

    • Write unit tests for view models and application services that don't require phone functionality
    • Execute tests directly in Visual Studio via Resharper or TD.NET
    • Execute the unit tests from the command line with XML out, without launching the emulator
    • Preferably be resiliant (as far as third party libraries go) to SDK updates

    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:

    • Open source ports of projects that are either incomplete or abandoned
    • Projects that are only available as an attachment on someone's blog

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

    解决方案

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

    Unit Testing

    Intent: To run isolated (no phone functionality), fast-executing tests often from both the IDE and Continuous Integration server without requiring the emulator (eg. TDD View Models)

    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.

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

    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.

    (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)

    Integration Testing

    Intent: To run longer-running tests that interact with resources external to the code (like phone features and web services) on the emulator, both on demand and on the CI server

    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.

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

    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.

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

    Acceptance/System Testing

    Intent: To run end-to-end automated tests that interact with the phone's UI on the emulator, both on demand or on the CI server

    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天全站免登陆