Progress Telerik JustMock

Mock Sealed Classes

Nasa, Visa, Microsoft Fox, Samsung, IBM World Bank Group, Volvo
  • Mocking Sealed Classes Overview

    Sealed classes have their specific role in software design. They are used to restrict  classes from being inherited. The sealed keyword tells the compiler that the class is sealed and therefore cannot be extended.

    The feature-rich capabilities of JustMock allow you to mock sealed classes and calls to their methods/properties, set expectations and verify results.

    public sealed class Rectangle : Shape
        public override double CalculateArea()
            return this.X * this.Y;
    public void MockMethodInSealedClass()
        // Arrange
        Rectangle rectangleMock = Mock.Create<Rectangle>();
        Mock.Arrange(() => rectangleMock.CalculateArea()).Returns(42);
        // Act
        double actualResult = rectangleMock.CalculateArea();
        // Assert
        Assert.AreEqual(42, actualResult);

    Mocking of sealed classes documentation

Next Steps

See Plans & Pricing

Purchase individual products or any of the bundles

Download Free Trial

With dedicated technical support.