clearMockHistory

Class: matlab.mock.TestCase
Package: matlab.mock

Clear history of mock object interactions

Syntax

clearMockHistory(testCase,mock)

Description

clearMockHistory(testCase,mock) clears the history of recorded mock object interactions. The clearMockHistory method does not clear mock object behaviors. To clear both interactions and behaviors, create a new mock.

Input Arguments

expand all

Instance of the test case, specified as a matlab.mock.TestCase object.

Mock to clear history of interactions from, specified as a mock object.

Examples

expand all

Construct a mock with a myMethod method.

testCase = matlab.mock.TestCase.forInteractiveUse;
[mock, behavior] = testCase.createMock("AddedMethods","myMethod");

Interact with the mock by calling the method. Then verify that the method was called.

mock.myMethod('abc');
testCase.verifyCalled(behavior.myMethod('abc'))
Verification passed.

View the interaction history.

h = testCase.getMockHistory(mock)
h = 

  SuccessfulMethodCall with properties:

       Name: "myMethod"
     Inputs: {[1×1 matlab.mock.classes.Mock]  'abc'}
    Outputs: {[]}

Interaction summary:
  myMethod([1×1 matlab.mock.classes.Mock], 'abc')

Clear the history of the recorded interaction and retest whether the method was called. The verification now fails.

testCase.clearMockHistory(mock)
testCase.verifyCalled(behavior.myMethod('abc'))
Verification failed.

    ---------------------
    Framework Diagnostic:
    ---------------------
    verifyCalled failed.
    --> Method 'myMethod' was never called.
    
    Specified method call:
    MethodCallBehavior
        [...] = myMethod(<Mock>, 'abc')

View the interaction history again. It is empty.

h = testCase.getMockHistory(mock)
h = 

  1×0 InteractionHistory array with properties:

    Name

Introduced in R2018b