27

Im trying to find a good mocking framework to Unittest my UWP App, bt it seems that all good Mocking infrastructures (MOQ, RhinoMocks etc) understandably rely on Dynamic Proxies which is not supported in UWP.

It looks like MOQ knows of this limitation: https://github.com/Moq/moq4/issues/195

And Microsoft is less than helpful in this situation: https://social.msdn.microsoft.com/Forums/en-US/652b9d16-c4ab-401c-9239-0af01108e460/uwp-is-there-any-indication-that-windows-10-uwp-universal-applications-will-support-code-emitting?forum=wpdevelop

Is there any Mocking infrastructure for unittesting UWP apps? Or any ideas if Dynamic Proxy support is coming anytime in the near future for UWP?

Thanks!

Filip Skakun
  • 31,624
  • 6
  • 74
  • 100
Scott Henry
  • 381
  • 3
  • 5
  • Have you tried MS Fakes – TYY Oct 20 '15 at 16:47
  • 3
    I get around this problem by organising my solutions so that all of my unit testable code is inside a portable class library, and not in the UWP/ WinRT project. – Roger Hartley Oct 21 '15 at 11:43
  • @TYY Is MS Fakes supported in UWP/WinRT? I cannot find any resources for adding it to a project, and it looks like it may be a requested (non-present) feature: http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/5894285-microsoft-fakes-for-windows-phone-unit-tests – Scott Henry Oct 21 '15 at 17:22
  • @RogerHartley That's OK for dekstop development but UWP and .NET Core is also about Windows on Devices, things like the Raspberry Pi, Android and iOS (whatever next!?). In that situation you really want to run your unit tests 'on the metal' so that means the unit test project has to be a UWP app (a la XUnit for Devices, https://xunit.github.io/docs/getting-started-devices.html). – Tim Long Dec 09 '15 at 23:06
  • 2
    [Moq](https://github.com/moq/moq4) framework now works in UWP applications, just make sure to install the pre-release version (4.6.38-alpha at the moment). I had to also remove all the "aot" runtime entries from my project.json, but I didn't need them anyway! – Shahin Dohan Jan 16 '17 at 06:22

2 Answers2

12

We (Microsoft BigPark Studio) have just released a mocking framework that is compatible with UWP, .NetCore and .Net Framework (Nuget Etg.SimpleStubs). The framework uses Roslyn to generate stubs.

To get around the Reflection.Emit restriction in UWP, the framework generates the stubs at compile time. The stubs are generated and compiled in one step (during the build). If you've ever used VS Fakes, the experience is very similar.

SimpleStubs is opensource and available as a NuGet:

Docs: https://github.com/Microsoft/SimpleStubs

NuGet: https://www.nuget.org/packages/SimpleStubs/

nbilal
  • 1,069
  • 2
  • 10
  • 21
7

There is now a framework called HyperMock which performs mocking in a similar way to other frameworks on the .NET platform.

Visit HyperMock

As this is available via Nuget, you can find it via the package manager with HyperMock.Universal or install it via the package console

Install-Package HyperMock.Universal

Use the Universal version for the UWP projects.

Mayjak
  • 1,487
  • 14
  • 17
Steve
  • 79
  • 1
  • 1
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/12475790) – service-paradis May 26 '16 at 00:32
  • 1
    As this is available via Nuget, you can find it via the package manager with **HyperMock.Universal** or install it via the package console **Install-Package HyperMock.Universal** – Steve May 26 '16 at 08:00
  • The link to GitHub isn't working! – Pedro Lamas Nov 06 '17 at 11:09