Progress Telerik JustMock

Mock Non-Virtual Methods and Properties

  • JustMock allows you to create mock object from any type and test your code in complete isolation from its dependencies to achieve the best possible design for your software without making any sacrifices.
  • 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 Non-Virtual Methods and Properties Overview

    Mocking non-virtual methods and non-abstract classes means that you can mock a concreate instance of whichever class you like. JustMock allows you to create any mock object and test your code in complete isolation from its dependencies to achieve the best possible design for your software without making any sacrifices.

    public class Context
    {
        public IList<int> myList = new List<int>();
     
        public void PopulateList(int count)
        {
            for (int i = 0; i < count; i++)
            {
                this.myList.Add(i);
            }
        }
    }
    ...
     
    [TestMethod]
    public void MockConcreteInstance_And_ValidateOccurance()
    {
        var expectedOccurrences = 10;
     
        // ARRANGE
        // Creating a mock instance of the "Context" class with Behavior.CallOriginal.
        var foo = Mock.Create<Context>(Behavior.CallOriginal);
     
        // Arranging: foo.myList.Add() should be called expected number of times no matter the argument.
        Mock.Arrange(()=> foo.myList.Add(Arg.AnyInt)).Occurs(expectedOccurrences);
     
        // ACT
        foo.PopulateList(expectedOccurrences);
     
        // ASSERT
        Mock.Assert(foo);
    }

    Concrete mocking documentation
Background-NextSteps

Next Steps

See Plans & Pricing

Purchase individual products or any of the bundles

Download Free Trial

With dedicated technical support.