Charlie
Charlie

Reputation: 10307

Windows Phone 7 mocking framework?

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.

Upvotes: 8

Views: 1451

Answers (5)

Mike
Mike

Reputation: 579

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

Upvotes: 0

Bob
Bob

Reputation: 1625

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.

Upvotes: 3

JustinAngel
JustinAngel

Reputation: 16092

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.

Upvotes: 14

Derek Lakin
Derek Lakin

Reputation: 16319

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.

Upvotes: 0

Matt Lacey
Matt Lacey

Reputation: 65564

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.

Upvotes: 4

Related Questions