Windows Phone 7 mocking framework?

柔情痞子 提交于 2019-12-01 01:31:23

问题


Are there any mocking frameworks for Windows Phone 7 or do I need to create fakes manually?

I've not found any on google, and although I found Moq listed on WP7 resources page, I couldn't get it working.


回答1:


There are no Mocking frameworks that support WP7 and I suspect there will never be any until WP7 supports Reflection.Emit.

On the .net framework there are many options that exist for the creation of a mocking framework (Profiler API, CodeDem, Refleciton.Emit, et al). The majority of these techniques won't work on Silverlight itself as it's missing quite a lot of the BCL/CLR. All existing Silverlight mocking frameworks use Reflection.Emit. WP7 does not support Reflection.Emit and thus no Silverlight mocking framework will work on WP7.

Because of that reason, I personally test WP7 assemblies on the Silverlight runtime. It's far from optimal (it sucks), but it's the best that can be done under the circumstances.

One could theoretically build a Mocking framework that uses Post-Build MSIL weaving that should work on WP7, but it's yet to be done.

If you'd like WP7 to support Reflection.Emit consider voting on this uservoice issue: WP7 should support Reflection.Emit for Mocking frameworks

EDIT 2/12/2011: Refleciton.Emit is supported on Mango. Hooray! Reflection.Emit based Mocking frameworks should just work.




回答2:


I'm not aware of any currently available.

This article by David Gadd shows an example of testing on the phone using manually created fake objects and may be a useful resource.




回答3:


I just got TypeMock Isolator, and it works with Windows Phone 7 (sortof).

You need to create a default Visual Studio Test project, and you will get an error saying that your Windows Phone 7 project can not be referenced, but for some reason the Mocks and Tests work perfectly.

Anyway, I'm really happy with the mocks it is able to create.




回答4:


Any mocking framework that supports Silverlight 3 should work with Windows Phone 7. You may need to use a previous version of the framework to "dumb it down" to Silverlight 3, though.




回答5:


Just wanted to notice some information that I found on MSDN:

http://msdn.microsoft.com/en-us/library/hh821022.aspx#sec2

The mock classes were manually developed as it is not possible to use a mocking framework on the Windows Phone platform. Mocking frameworks require the ability to emit Microsoft intermediate language (MSIL) code, which is not currently possible on the Windows Phone platform



来源:https://stackoverflow.com/questions/4724574/windows-phone-7-mocking-framework

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