JustMock for Devices is a version of JustMock that allows you to use the familiar JustMock syntax to create, arrange and use mocks in tests that run on devices. It supports Windows Phone and Xamarin Android/iOS, and works both in the emulator/simulator and on the devices. You can use it both with Visual Studio on Windows and with Xamarin Studio on Mac.
The feature set of JustMock for Devices is similar to that of JustMock Lite–you can mock interfaces, virtual members on classes that can be sub-classed and delegates. All arrangement and assertion features are supported except a few exotic ones (fore example, Wait.For and SetInterceptionFilter).
The package will be delivered through the JustMock and JustMock Trial installers. Now it is available in the latest internal build of JustMock in a Beta stage.
Installation in all cases is done through the NuGet package manager, but you need to install JustMock first.
The internal build installer may not add the NuGet package source for JustMock, so you may need to add it manually. Skip this step if the JustMock package source is already present in the list of package sources.
Open Tools menu -> Options -> NuGet Package Manager -> Package Sources
The dialog should look like it does in the screenshot above.
So, you have a Windows Phone Unit Test project and you want to use JustMock for mocking.
Right-click on the References node of your unit test project in the Solution Explorer and select "Manage NuGet Packages." Select the "JustMock IB" package source under the "Online" section.
There are two packages you can install.
Install either of these packages to continue. If you’re not sure what to use, install JustMock Auto-Mocking for Devices for the full experience.
Once installed, your project should look something like this:
You will get a reference to Telerik.JustMock.Portable and, optionally, to Autofac and Telerik.JustMock.Portable.Autofac. You will also get a file named FodyWeavers.xml. This file is part of the JustMock machinery and should be committed as part of your project.
You’re ready to do some mocking. Here’s a silly test I wrote:
var serviceProvider = Mock.Create<IServiceProvider>();
Mock.Arrange(() => serviceProvider.GetService(
Select the emulator:
And run the tests:
All is green!:
If you check the build log, you’ll see something along the following lines:
1>------ Build started: Project: UnitTestApp3, Configuration: Debug x86 ------
1> Fody (version 184.108.40.206) Executing
1> Finished Fody 598ms.
1> UnitTestApp3 -> C:\Users\dragnev\documents\visual studio 2013\Projects\UnitTestApp3\UnitTestApp3\bin\x86\Debug\UnitTestApp3.dll
1> Skipped Verifying assembly since it is disabled in configuration
1> Finished verification in 3ms.
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
Notice that there are a few lines mentioning Fody–this is part of the special sauce that enables the creation of mocks on devices, where you can’t execute dynamically generated code.
The installation process in Xamarin Studio is about the same as the one for Visual Studio, because both are based on NuGet. Macs, however, cannot execute PowerShell scripts, so you will need one additional simple step to get JustMock up and running.
Copy the JustMock NuGet packages to a new folder on your Mac (in a Windows installation they can be found in “C:\Program Files (x86)\Telerik\JustMock\Libraries\NuGet”). Configure a new NuGet Package Source to point to that folder:
Select the JustMock package source. The JustMock packages should pop up in the list:
Refer to the Visual Studio section, if you’re wondering which package to install.
After installing the package of your choice, you will get a warning, which is normal and should be disregarded:
Your project should now look something like this:
Just a few manual setup things before we’re ready to mock.
Delete the Fody_ToBeDeleted.txt file.
Open the FodyWeavers.xml file and paste the following settings in:
You’re ready to mock! Here’s another silly test:
var mock = Mock.Create<IUIKeyInput> ();
Mock.Arrange (() => mock.HesText).Returns (
Select an iOS Simulator and hit “Run.”
The simulator will boot up and you’ll be able to run the test:
JustMock for Devices is still in Beta and we welcome all sorts of feedback that will allow us to stabilize and improve it. If you run into any issues, please open a ticket describing the problem, your setup and anything else that will help us reproduce the issue.
The Just* Team
Stefan Dragnev is a Principal Software Engineer at Telerik.
Copyright © 2016, Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks or appropriate markings.