Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 994
Charlie Avatar asked Jan 18 '11 13:01

Charlie


People also ask

What are mocking frameworks?

What is a mocking framework? Mocking frameworks are used to generate replacement objects like Stubs and Mocks. Mocking frameworks complement unit testing frameworks by isolating dependencies but are not substitutes for unit testing frameworks.

Which framework is used to create mocked objects?

Creating mock objects manually is very difficult and time-consuming. So, to increase your productivity, you can go for the automatic generation of mock objects by using a Mocking Framework. A developer can build his/her unit test by using any of the NUnit, MbUnit, MSTest, xUnit etc.

Why do we need mocking framework?

The benefits of a mocking framework are: Easier (subjective, but after a while you will not write hand written implementations) Less Code (frameworks allow you to create a mock in a matter of lines, rather than full class declarations) Follows DRY (you won't end up repeating mock implementations)

How is a mocking framework used for verification?

Verify methods were called Mocking frameworks add another way to test - checking whether methods were called, in which order, how many times and with which arguments. For example, let's say that a new test is required for adding a new user: if that user does not exist than call IDataAccess. AddNewUser method.


2 Answers

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.

like image 132
JustinAngel Avatar answered Oct 11 '22 21:10

JustinAngel


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.

like image 38
Matt Lacey Avatar answered Oct 11 '22 20:10

Matt Lacey