background

Telerik JustMock

Recursive Mocking

  • Recursive mocking is a productivity feature that enables you to mock a chained call to a member.
  • Part of the fastest, most flexible and complete mocking tool for crafting unit tests.
  • Our award-winning support team is available to assist you with any issues.
Mocking and Assert Functionality
  • Recursive Mocking Overview

    Recursive mocking is a productivity feature that allows you to mock a chained call to a member. This saves you the effort to create new objects, associating them to members, and executing additional logic for the "chain" to be fully prepared for access.

    [TestMethod]
    public void ShouldAssertNestedPropertyGet()
    {
        var expected = 10;
     
        // ARRANGE
        // Creating a mocked instance of the "IFoo" interface.
        var foo = Mock.Create<IFoo>();
     
        // Arranging: When foo.Bar.Value is called, it should return expected value.
        //              This will automatically create mock of foo.Bar
        //              and a NullReferenceException will be avoided.
        Mock.Arrange(() => foo.Bar.Value).Returns(expected);
     
        // ACT
        var actual = foo.Bar.Value;
     
        // ASSERT
        Assert.AreEqual(expected, actual);
    }

    Recursive mocking documentation
Next Steps