background

Telerik JustMock

Mock Sealed Classes

  • The feature-rich capabilities of JustMock allow you to mock sealed classes and calls to their methods/properties, set expectations and verify results.
  • 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.
Mock everything
  • 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;
        }
    }
      
    ...
      
    [TestMethod]
    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