MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

You can define behavior based on the number of outputs requested in a method call. If the
method call requests two output values, return "??" for the name and -1 for the ID.


testCase.assignOutputsWhen(withNargout(2, ...
withAnyInputs(behaviorObj.findUser)),"??",-1)
[n,id] = mock.findUser(13)


n =


"??"


id =


-1


Define Mock Property Behavior


When a mock property is accessed, you can specify that it returns specific or stored
property values. When it is set, you can specify when the mock stores the property value.
You can also define when the testing framework throws an exception for mock property
set or access activities.


When defining mock property behavior, keep in mind that displaying a property value in
the command window is a property access (get) operation.


Similar to defining mock method behavior, defining mock property behavior requires an
instance of the PropertyBehavior class. The framework returns an instance of this
class when you access a mock property. To define access behavior, use an instance of
PropertyGetBehavior by calling the get method of the PropertyBehavior class. To
define set behavior, use an instance of the PropertySetBehavior by calling the set or
setToValue method of the PropertyBehavior class.


Specify that when the Name property is set to any value, the testing framework throws an
exception.



  • The throwExceptionWhen method instructs the framework to throw an exception for
    a specified behavior.

  • Accessing a property on the behavior object PropertyBehavior class
    (behaviorObj.Name) creates a PropertyBehavior class instance.

  • The call to the set method of the PropertyBehavior class creates a
    PropertySetBehavior.


Specify Mock Object Behavior
Free download pdf