Main Content

Simulierte Abhängigkeiten in Tests

Mit dem Mocking-Framework können Sie ein Teil eines zu testenden Systems isolieren, indem Sie das Verhalten abhängiger Komponenten simulieren

Beim Unit-Test wollen Sie häufig einen Teil eines vollständigen Systems isoliert betrachten, d. h. ohne Abhängigkeiten berücksichtigen zu müssen. Zum Testen eines Systemteils können wir die Abhängigkeiten mithilfe von Mock-Objekten ersetzen. Ein Mock-Objekt dient der Umsetzung von mindestens einem Teil einer Schnittstelle des Produktionsobjekts, jedoch häufig auf einfachere, schnellere, besser vorhersehbare bzw. besser steuerbare Weise.

Informationen zum Einstieg finden Sie unter Create Mock Object.

Test a component using mocked-up dependencies.

Klassen

alle erweitern

matlab.mock.TestCaseClass for writing tests with mocking framework
matlab.mock.AnyArgumentsMatch any number of arguments
matlab.mock.actions.AssignOutputsDefine return values for method called or property accessed
matlab.mock.actions.DoNothingTake no action (Seit R2020a)
matlab.mock.actions.Invoke Invoke function handle when method is called
matlab.mock.actions.ReturnStoredValueReturn stored property value
matlab.mock.actions.StoreValueStore property value
matlab.mock.actions.ThrowExceptionThrow exception when method is called or when property is set or accessed
matlab.mock.constraints.Occurred Constraint qualifying mock object interactions
matlab.mock.constraints.WasAccessedConstraint determining property get access
matlab.mock.constraints.WasCalledConstraint determining method call
matlab.mock.constraints.WasSetConstraint determining property set interaction
matlab.mock.MethodCallBehaviorSpecify mock object method behavior and qualify method calls
matlab.mock.PropertyBehaviorSpecify mock object property behavior and qualify interactions
matlab.mock.PropertyGetBehaviorSpecify mock property get behavior
matlab.mock.PropertySetBehaviorSpecify mock object set behavior
getMockHistoryReturn history of mock object interactions
matlab.mock.InteractionHistory.forMockReturn history from mock object
matlab.mock.InteractionHistory Interface for mock object interaction history
matlab.mock.historySummary of classes representing mock object interaction history

Themen