Progress Telerik JustMock

Mock Local Functions

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;
    public class MockLocalFunctions
        public void BasicUsage()
            var sut = Mock.Create<Foo>(Behavior.CallOriginal);
            Mock.Local.Function.Arrange<int>(sut, "GetResult", "GetLocal").DoNothing();
            var result = sut. GetResult();
            Assert.AreEqual(100, result);

    Mock local functions documentation

Next Steps

See Plans & Pricing

Purchase individual products or any of the bundles

Download Free Trial

With dedicated technical support.