Progress Telerik JustMock

Assert Occurrence

  • JustMock allows you simple and fast assertion of how many times the method is called without the cost of developing and maintaining additional code.
  • 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.
Mocking and Assert Functionality
Nasa, Visa, Microsoft Fox, Samsung, IBM World Bank Group, Volvo
  • Assert Occurrence Overview

    In many situations, especially in complex projects with numerous features interacting with each other, a method can be called too many or too few times, resulting in unexpected behavior of the software. To verify that the method in question is called the exact number of times, additional code is typically written and maintained to handle that verification.

    JustMock allows you simple and fast assertion of how many times the method is called without the cost of developing and maintaining additional code.
  • Set Assertion Expectation During Arrange

    One of the possible options when verifying the occurrence of a method call is to set the expectation at the arrange phase and verify all assertion expectation for the mock object at the end of the test.
    [TestMethod]
    public void Test_ExecutionOfAddProduct_OccursOnce()
    {
        // Arrange
        Order order = Mock.Create<Order>(Behavior.CallOriginal);
        Mock.Arrange(() => order.AddProduct(Arg.IsAny<Product>(), Arg.AnyInt)).OccursOnce();
     
        // Action
        Product product = new Product("socks");
        order.AddProduct(product, 2);
     
        // Assert
        Mock.Assert(order);
    }
  • Assert the Occurrence Expectation at the End of the Test

    Another option is to directly assert that a specific method of a mock object is called certain times at the end of the test.
    [TestMethod]
    public void Test_ExecutionOfAddProduct_OccursOnce()
    {
        // Arrange
        Order order = Mock.Create<Order>(Behavior.CallOriginal);
     
        // Action
        Product product = new Product("socks");
        order.AddProduct(product, 2);
     
        // Assert
        Mock.Assert(() => order.AddProduct(product, 2), Occurs.Once());
    }

    Asserting occurrence documentation
Background-NextSteps

Next Steps

See Plans & Pricing

Purchase individual products or any of the bundles

Download Free Trial

With dedicated technical support.