Progress Telerik JustMock

Mock Local Functions

  • JustMock makes isolating your unit test from a dependency to a local function an easy task, allowing you to mock it. In most cases, mocking local functions is similar to mocking class methods.
  • This feature is a part of the fastest, most flexible and complete mocking tool for crafting unit tests.
  • Our award-winning support team is dedicated to assisting you with any questions and issues you may have during your application development.
Mock everything
Nasa, Visa, Microsoft Fox, Samsung, IBM World Bank Group, Volvo
  • Mocking Local Functions Overview

    A local function is a private function whose scope is limited to the scope of the function in which it is created. The local function can be called only within the container member and with this—a dependency to the container member.

    JustMock makes isolating your unit test from the local function an easy task, allowing you to mock it. In most cases, mocking local functions is similar to mocking class methods.

    class Foo
    {
        public int GetResult()
        {
            return 100 + GetLocal();
            int GetLocal ()
            {
                return 42;
            }
        }
    }
     
    ...
     
    [TestClass]
    public class MockLocalFunctions
    {
        [TestMethod]
        public void BasicUsage()
        {
            //Arrange
            var sut = Mock.Create<Foo>(Behavior.CallOriginal);
            Mock.Local.Function.Arrange<int>(sut, "GetResult", "GetLocal").DoNothing();
      
            //Act
            var result = sut. GetResult();
      
            //Assert
            Assert.AreEqual(100, result);
        }
    }

    Mock local functions documentation
Background-NextSteps

Next Steps

See Plans & Pricing

Purchase individual products or any of the bundles

Download Free Trial

With dedicated technical support.