Telerik® JustCode™ by Progress

Telerik® JustCode™ provides support for Telerik JustMock by automatically generating mocks and arrangements. This makes the writing of JustMock unit tests much easier.

Getting Started

The only thing you need, in order to use this functionality, is the Telerik.JustMock.dll referred to the current project. Then, creating or arranging a mock through JustCode will automatically include the required usings (Telerik.JustMock; and Telerik.JustMock.Helpers; if fluent syntax is used).

Both, the Create Mock and the Arrange Mock commands are placed inside the Visual Aid menu of JustCode.


Language Support

Supported: C#, VB.NET

Not relevant: ASP.NET, XAML, JavaScript, HTML

To Create Mocks

  1. Use the Create Mock command. Press Alt+End. From the pop-up menu, select Create Mock. It is available for similar to the following declaration:

    Just Code Integration Create MockVAMenu
  2. Executing the command will result in a creation of a mock with default behavior :

    Just Code Integration Create Mock Result

To Arrange Mocks

  1. Use the Arrange Mock command. Press Alt+End. From the pop-up menu, select Arrange Mock

    Just Code Integration Arrange MockVAMenu

    Let's assume we have the following Foo class:

    Just Code Integration SUT
  2. Clicking on the Arrange Mock command will prompt a window, containing all mockable members of the instance. You will notice Telerik® JustCode™ shows non public methods and properties as well. You can also choose between standard arrangements or fluent syntax .

    The next image describes the functionalities inside the Arrange Mock configuration window:

    Just Code Integration Arrange Mock Select Members Interface With Options
  3. When you click the Finish button, the following code will be automatically generated for it:

    Just Code Integration Arrange Mock Result

You can use the Arrange Mock command on every mock declaration:

  • Foo myMock = Mock.Create<Foo>();

  • var myMock = Mock.Create<Foo>();

  • Foo myMock; - here the mock is not even created. Its creation will be automatically generated by JustCode.

  • Foo myMock = new Foo(); or var myMock = new Foo(); - for this initialization, Telerik® JustCode™ will automatically apply partial mocking for the arranged methods.

Expected Arrangement's Behavior

The template for the Arrange Mock command is as follows:

  • Arranging functions or property getters:

    • Value type functions/properties are arranged to return the default value for their type:


      • Mock.Arrange(() => myMock.IntProperty).Returns(0);

      • Mock.Arrange(() => myMock.IntFunction()).Returns(0);

    • For string functions/properties the expected return value is String.Empty or "":


      • Mock.Arrange(() => myMock.StringProperty).Returns("");

      • Mock.Arrange(() => myMock.StringFunction()).Returns("");

    • Reference type functions/properties will return a new mock of their type:


      • Bar expectedRefProperty = Mock.Create<Bar>();

      • Mock.Arrange(() => myMock.RefProperty).Returns(expectedRefProperty);

      • Bar expectedRefFunction = Mock.Create<Bar>();

      • Mock.Arrange(() => myMock.RefFunction()).Returns(expectedRefFunction);

  • Arranging void methods:

    • By default, void methods will be arranged to .DoNothing() .


      • Mock.Arrange(() => myMock.VoidMethod()).DoNothing();

  • Arranging property setters:

    At this stage, JustMock allows arranging for property setters only if they are public. The JustCode's Arrange Mock command will generate the following for them:

    • Value type properties are set the default value for their type:


      • Mock.ArrangeSet(() => myMock.IntProp = 0);

    • For string properties the expected set value is String.Empty or "":


      • Mock.Arrange(() => myMock.Category = "");

    • Reference type properties will be set to the default of their type:


      • Mock.Arrange(() => myMock.RefProperty = default(Bar));

  • Matching arguments

    • For the expected method/function arguments JustCode uses the matchers , inside JustMock:


      • Mock.Arrange(() => myMock.DoSomething(Arg.AnyBool, Arg.AnyString, Arg.IsAny<Bar>())).DoNothing();

See Also