Telerik® JustMock™ by Progress

You can use Telerik JustMock in Windows Runtime to perform elevated or non-elevated testing.

How To:

Having an Unit Test Library (Windows Store apps) project, you need to refer the Telerik.JustMock assembly(ies). Then you will be able to mock everything as in normal .NET or Silverlight project.

Non-Elevated Examples

The next examples can be applied with both JustMock Lite and JustMock commercial (Commercial vs Free Version). For them, we will use the following system under test:

Mocking Void Method from an Interface

To mock an interface under Windows Runtime, we use Mock.Create<T>() as in .NET or Silverlight projects.
In the above test, we create a mocked instance of the IFoo interface. Then, we arrange that, DoSomething() must be called during the test execution and it should do nothing. After acting on the system under test, we assert the expected behavior.

Mocking Functions from an Interface

Here we perform a mocking of an interface string method:
Again, we create a mocked instance of the IFoo interface. Then, we arrange that, ReturnMyString() must be called during the test execution and it should return "Test". Note that, we ignore the arguments by expecting any string to be passed. After acting on the system under test, we assert that the actual and the expected return value are the same.

Elevated Examples

Note

This feature is available only in the commercial version of Telerik JustMock.

Refer to this topic to learn more about the differences between both the commercial and free versions of Telerik JustMock.

Important

You first need to go to elevated mode by enabling Telerik JustMock from the menu. How to Enable/Disable Telerik JustMock?

For the examples, we will use the following system under test:

Mocking Static Property

To mock a static property inside Windows Runtime you can refer to the following:
We directly arrange that, StatProp must be called during the test execution and it should return "Test". Then, the only thing needed is to act on the system under test and assert the results.

Mocking Static Method

To mock a static method you use similar syntax as when mocking properties. However, as we are mocking a void method we arrange it to do nothing this time:
Further, you can also specify expected method arguments, as described here.

See Also